-
Notifications
You must be signed in to change notification settings - Fork 115
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
The problem with cyclic injects checker #420
Comments
Hi, this usecase is a bit strange to me, could you please explain the real usecase ? What do you need to achieve ?Why not to just inject Iface in the parentscope as well as in the child scope ? If the binding is done in the parent, the child scope will benefit from this binding if not overriden.Additionally, a the scope structure is a tree, it allow by design to have second child scope. How would you solve this ?Everyscope have to be sufficient, so a rootscope has to live/survive without any child scope from my point of view (at least)
|
@afaucogney Hi. I will try to explain my case
My solution is to create the function
this code is similar to dagger's Component
The code from my App
I don't want to bind everything from AdsModule to |
Your usecase is fine to me, but the following is not clear to me:
To Inject the IAdsManager, in your app, you have to definitively bind it in the root scope.
By doing the job in the module, you can hide the complexity on the manager instantiation, but nevertheless you have to init the sdk somewhere. AdsManager.setup() ou AdsManager.inject()... You may bind the IAdsManager to a provider or directly to the instance, as you want. Then IAdsManager should be available at rootscope level everywhere in the app. (do not forget to call inject()). PS: To remind what I have tried to explain early, a top scope of a tree, cannot/must not depend from one of its child, because by design this top scope may have other children or no child at all, and it should be kept persistent. I hope I helped a bit. |
Here is I want to bind an interface without creating of instance right now. Because it's possible that IAdsManager will never instantiate because we don't open some screen. IAdsManager - it's just for example. Overall I'm talking about an approach to solve this problem. This code is solving the problem, but it creates the instance right in the app. I don't like it.
I agree, and I think the toothpick is not designed to solve my problem clearly. |
I think this is not the design concept of ktp that block you in finding solutions. My point was more about general concept. I think there are 2 possible solutions to your problems : 1/ use a lazy injection.
2/ bind your manager in the viewmodel of the dedicated screen. (Not before) |
fix |
Really unfortunate that this is still an issue :( In my case, I needed to added same bind in submodule onto the same interface for ImageLoader to provide automatic analytics logger for images. IMHO it's pretty reasonable scenario |
Hello!
Unfortunately, I got an unexpected crash with toothpick.
How to reproduce the crash
this code throws
this code is working, but it creates instance immediately
If I remove any cycles checking from toothpick, everything is working as I expected
the problem with this code from
RuntimeCheckOnConfiguration.java
we are trying to get
IFace
instance fromchild
scope, but we already trying to get it from parent scopecycles checking code can't understand it :)
The text was updated successfully, but these errors were encountered: