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

Added RegistrationBuilder variations with callback support #569

Open AlonTalmi opened 10 months ago

AlonTalmi commented 10 months ago

I added the option to listen to resolve callback when binding new types. It's useful if you want to use the instance when it's created without coupling it to the type implementation itself.

I decided to implement it using new variations of RegistrationBuilder, one is called RegistrationBuilderWithCallback the other is called FuncRegistrationBuilderWithCallback, no need for instance callback.

The con of doing it this way is that there's more permutations if someone want to create new type of RegistrationBuilders and still support callbacks.

The other ways I could have implemented it is:

Tested on my game and wrote Unit Tests

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 Nov 15, 2023 7:30am
hadashiA commented 4 months ago

I think it's good, but if the callback argument of the API is just added, it's not obvious when it will be called. Currently, lambda expressions tend to be used primarily for additional configuration to be done programmatically and not for callback purposes.

Register(..). .OnResolve(callback) form would be better, or something like that. I wonder.