hadashiA / VContainer

The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
https://vcontainer.hadashikick.jp
MIT License
1.89k stars 165 forks source link

Installer component (like Zenject's MonoInstaller) #579

Closed AlonTalmi closed 5 months ago

AlonTalmi commented 10 months ago

This is the equivalent of Zenject's MonoInstaller

Also added: InstallerGroup component that batch multiple installers together (I mostly used it in prefabs, that way I can create a group at the root of the prefab and I don't need to reference the nested installers in the prefab 1 by 1)

GetInstallerComponentsGroup component that batches all installers in GameObject using GetComponent

BuildCallbackInstaller component that is used for actions that run on the Container's build callback

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vcontainer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2023 9:21pm
pnarimani commented 10 months ago

I don't think this is necessary to be honest. You can always create a LifetimeScope that does a GetComponent or whatever it needs to do in the Configure method.

AlonTalmi commented 10 months ago

Maybe the name is confusing, this is not an installer that specifically installs components, but an abstract MonoBehaviour component that inherits from IInstaller.

I like to split my LifetimeScopes into multiple installers, which many times can be recycled in other scopes and reduce boilerplate.

srodriguezf commented 6 months ago

Hi, we are thinking changing to VContainer. Now, we are using Zenject. This feature is very important for us because we use a lot of installers and we cant write everything in the lifetimeScope. Would like when it is going to be the merge pull request. Thanks.

AlonTalmi commented 6 months ago

@srodriguezf You can very easily implement this feature yourself by inheriting from LifetimeScope

hadashiA commented 5 months ago

Thanks.

Several people seem to be in favour of this feature, Regrettably, I do not actively recommend separating DI settings. So, I would like to reject this. Sorry. (The OnBuild method, however, might not be a bad idea.)

As discussed in this thread, if users want to separate them in any way they like, they can.