Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My modular cannot register Client and Network #933

Closed
raj-ueslem opened this issue Jan 31, 2024 · 6 comments
Closed

My modular cannot register Client and Network #933

raj-ueslem opened this issue Jan 31, 2024 · 6 comments
Labels
new New issue request attention question Questions about using some feature or general working of the package

Comments

@raj-ueslem
Copy link

I'm doing a project that consumes data that I created in mockapi but I'm not able to make the modular register my http.Client class that comes from http nor my Network that needs http, the other classes were created and instantiated without problems.

appmodular binds novo

appmodular erro novo

in some situations it registers but says that the class already exists but if you remove anything for example:

i.add(http.Client.new);
i.addInstance(http.Client());
i.add<Network>(Network.new);
i.addInstance<Network>(Network(i.get()));

and change to:

i.add(http.Client.new);
i.addInstance(http.Client());
i.add<Network>(Network.new);

in this situation it says that the class was not instantiated, regardless of what you add or remove, the errors always remain between saying that the class was not registered or that it already exists. I don't know what it could be, I must have already tried almost everything I know from the old one and what I studied from the new modular :(

@raj-ueslem raj-ueslem added new New issue request attention question Questions about using some feature or general working of the package labels Jan 31, 2024
@edugemini
Copy link
Contributor

try only:

i.add<Client>(http.Client.new);
i.add<Network>(Network.new);

@raj-ueslem
Copy link
Author

raj-ueslem commented Feb 1, 2024

try only:

i.add<Client>(http.Client.new);
i.add<Network>(Network.new);

unfortunately it didn't work, I'm starting to think it might be a bug that happened.
Even with the command you gave me, it continues saying that the class is not registered, but if I go and run it at a lower level of the project, the register part works but it conflicts with the instance that is declared next, it requires both at the same time and falls into the situation where the class already exists in the injector

@edugemini
Copy link
Contributor

Could you provide a complete code so that I can reproduce the error?

@raj-ueslem
Copy link
Author

Could you provide a complete code so that I can reproduce the error?

app.zip

this is the file with the part that has the error, I made several changes to it to try to find out the reason for the error, for example, now I am no longer calling network in app_modular but in home_module to see if the behavior changes.

@edugemini
Copy link
Contributor

Hi @raj-ueslem

In lib/core/app/home/module/home_module.dart, do:

void binds(Injector i) {
    i.add<http.Client>(http.Client.new);
    i.add<Network>(Network.new);
    i.add<HomeInterface>(HomeService.new);
    i.addSingleton(HomeStoreAction.new);
    i.addSingleton(HomeStoreState.new);
}

@raj-ueslem
Copy link
Author

Hi @raj-ueslem

In lib/core/app/home/module/home_module.dart, do:

void binds(Injector i) {
    i.add<http.Client>(http.Client.new);
    i.add<Network>(Network.new);
    i.add<HomeInterface>(HomeService.new);
    i.addSingleton(HomeStoreAction.new);
    i.addSingleton(HomeStoreState.new);
}

It worked, wow, I'm very happy hahaha

If you still have some patience left, could you explain to me why it wasn't working before? I don't think I understood very well. From what I saw, the instances I was using were unnecessary xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention question Questions about using some feature or general working of the package
Projects
None yet
Development

No branches or pull requests

2 participants