Skip to content

Conversation

@AlonTalmi
Copy link
Contributor

@AlonTalmi AlonTalmi commented Nov 14, 2023

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:

  • Adding a WithCallback method in the base RegistrationBuilder, but because I don't know the type of the object I could only use Action<object, IObjectResolver>
  • By creating a decorator to the final created Registration by extracting an interface, but then I would have had to replace every reference to Registration to IRegistration (which also breaks backwards compatibility)

Tested on my game and wrote Unit Tests

@vercel
Copy link

vercel bot commented Nov 14, 2023

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
Copy link
Owner

hadashiA commented May 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants