gustavopsantos / Reflex

Minimal dependency injection framework for Unity
MIT License
730 stars 51 forks source link

Added generic add functions #35

Closed WhiteOlivierus closed 1 year ago

WhiteOlivierus commented 1 year ago

Pull Request Template

Description

I took some inspiration from how the Microsoft DI container registration works and added those functions to Reflex. The options I added are:

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

gustavopsantos commented 1 year ago

Awesome to see you started the implementation for adding function support, however I think its better to create a specific new API like AddSingleton,AddTransient. Something like AddFunction. To add this new functionality without poluting the current APIs. Also when adding function support, we need to add debug support, so the debugger window should be able to display the correct informations. So in min mind the following steps needs to be followed. 1 - Update debugger window to display the objects created under each binding (VContainer has something pretty similar) 2 - Add new AddFunction API 3 - Test both the AddFunction API and also resolving it

WhiteOlivierus commented 1 year ago

Hey thank you for the quick reply.

I extended the current api, and this is still backwards compatible like this. Because the idea is too have specific constructions for all of the lifetimes that you can register. If we would make a addfunction method we should give it a lifetime when creating it, while we could just make a specific function like I did now.

gustavopsantos commented 1 year ago

Overloading current APIs and extending current resolvers will affect both, current behaviour and performance. Basically we want to provide a functionality where user can detach the object creation from container controlling it by himself while keeping created objects disposal within parent container. I will provide a new API AddFunction or AddFactory that will allow this without changing current behaviour and perf for existing Resolvers (Transient, Singleton and Instance)

WhiteOlivierus commented 1 year ago

I'm so sorry, I was swamped lately, but here I have an example of what I mean why I want this way of registering services. Now I get an error when running the container that something is wrong. But with the generic functions, it would never let me register this which would not be resolvable.

example