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.92k stars 167 forks source link

Use Contract names for parenting instead of LifetimeScope derived class type #643

Open Maesla opened 6 months ago

Maesla commented 6 months ago

One of the most useful features from Zenject was parenting by contract name https://github.com/Mathijs-Bakker/Extenject?tab=readme-ov-file#scene-parenting-using-contract-names

image

With contract names, you could define which contract the LifteTimeScope resolves and in the parenting relationship, which contract the LifteTimeScope expects to be resolved

This would allow a lossy couple relationship between child and parent. You can define the parent contract but it is not necessary to implement an specific LifteTimeScope to register the instances

For example, you can define the Parent Contract as "Settings" and these settings could be registered by SettingsLifeTimeScope or by DebugSettingsLifeTimeScope

This would also allow for me the more important feature, to have a list of default contract names, maybe in the VContainerSettings, where you can define a key value collection of default LifteTimeScope that matches the contract. If the contract is not found and it is defined in the list, it is created. This is extremely useful for multi scene architecture where one scene depends on the other and you want to run the scene independently with debug values