dolittle-obsolete / DotNET.Fundamentals

Reusable, fundamental abstractions and building blocks
http://www.dolittle.io
MIT License
4 stars 8 forks source link

Self binding for all bindings based on type #304

Closed einari closed 4 years ago

einari commented 4 years ago

This adds .AsSelf() for all type based bindings. This allows one to ask the container for an instance based on the concrete type in addition to its implementing interface and it will use the same binding for this.

The problem we ran into was when leveraging IInstancesOf<> which calls the container and asks for a concrete instance and the type also has an interface that typically follows the convention IFoo -> Foo in addition to an interface used as marking for discovery, taking a dependency to IFoo in another place would not follow same binding and honor the same lifecycle - for instance Singleton or SingletonPerTenant.

┆Issue is synchronized with this Asana task

einari commented 4 years ago

Good point, let me add that capability as well - that makes sense and would be the least surprising outcome for developers.

einari commented 4 years ago

Note to self: use .GroupBy() for the type in the ContainerBuilderExtensions for the .To() type and then bind all interfaces to that type.

einari commented 4 years ago

Could we pull this as is? It means we would get some more metrics in the Runtime working as this PR does: https://github.com/dolittle-runtime/Runtime/pull/367

And create new tasks for the missing pieces? (@petriw)

/cc: @jakhog @woksin