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
2.02k stars 176 forks source link

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

Closed Hitomilras closed 2 months ago

Hitomilras commented 2 months 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 2 months ago

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