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.96k stars 172 forks source link

How to disable force injection for type registered by RegisterComponentInHierarchy #704

Closed Hitomilras closed 1 month ago

Hitomilras commented 1 month ago

Imagine you have some entity in the game that must be injected into another entities. For example, ProjectileManager.

This ProjectileManager registered using different lifetime scopes using "builder.RegisterComponentInHierarchy();". Now each LifetimeScope that have this type registered try to inject it.

How to override this behavior? I understand why plain C# types are injected when they are registered (because they are resolved by creating new instance), but for MonoBehavior it's not always required and I need to find a way to disable auto injection of registered MonoBehavior, how can i do it?

Hitomilras commented 1 month ago

I found the way: use RegisterInstance, this won't force inject registered instance.