-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Simple registration, how? #558
Comments
Maybe just use constructor ?))))))))))) |
Obviously this is sample. It's possible that OP cannot use ClassA and ClassB constructors due to them being third party code. |
Exactly. |
use factory!) Lol. |
|
Main question here is that VContainer is focus on non-lazy instance creation. Anyway SetA and SetB should be good to inject from method. This move will encapsule logic, because injection from properties isn't good as it looks like. Anyway you can inject properties. For such cases I use such extension - https://pastebin.com/irNEeivs |
@IaroslavGusiev It seems to me that you don't understand the problem at all. I'm not trying to do an injection of a class properties or something like this :\ I'm trying to figure out how to register dependency from Resolve. |
What is the problem with this issue? You haven't explained it?
Or maybe it's a different issue. |
@hadashiA issue was updated |
If you just want to manually handle the lifecycle you can register the instance, as that is not managed by the container.
|
@Valerio-Corso What you wrote here won't even compile :\ VContainer aren't Zenject. |
sorry my bad, that was from top of my head and syntax may be wrong but the idea of registering an instance stands. Otherwise, not sure if these solution fits your case but what i would try:
|
@Valerio-Corso #554 this is how it could work in my opinion. Author rejected this pull, so there should be another way to solve this problem simply using existing options. Lifetimescope have a different role, so the solution through them will be a bad idea. What should I do if I have a lot of such cases?
If you look at the very first post, then the option is considered there and it is written why it will not work. |
@hadashiA mb you need more context? |
Perhaps you will find the answer at this link? https://vcontainer.hadashikick.jp/registering/register-type#register-instance
|
Sorry, I doubt I understand the context well enough. But does this mean that the third-party plugin sets up a DI container and the application registers against it? In my opinion, DI is not necessary for mere third-party plug-ins or libraries. Even if such a mechanism were used, the DI container should not be shared between the library application side and the library side. Dependency inversion with a DI container is only for writing applications. The exception, of course, is frameworks. But in this case, the lifespan management should match, because it provides the application with the lifespan management of the framework. |
We have a kind of third-party plugin that is a provider for various plug-in subsystems. These subsystems are created by the provider itself and this provider manages their lifecycle.
Issue: if we register them in a container, the container will take over the lifecycle management of these dependencies. Which will cause
Dispose
to be called in the container and in a third-party provider. This is incorrect behavior, because in this situation the container is not the producer of the object and should not take responsibility for the release.The question is, how to register so that the
vContainer
does not manage the lifecycle?Example:
And registrations, which naturally won't work:
Injecting ClassContainer everywhere is obviously a bad idea.
The text was updated successfully, but these errors were encountered: