You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the major qualms I have had with the Microsoft dependency injection implementation is that it has a one-type / one-registration policy. If I have two implementations of IFoo, I cannot register them both simultaneously. Instead, I need to recreate them every time I need them.
StructureMap, because it is not terrible, uses the concept of "named" registrations to get around this problem. When you register an implementation of a service to an interface, you can "name" that registration with a string.
We could add this functionality to the Microsoft implementation by creating some kind of disposable dictionary of type IDictionary<string, TValue>. For each registration of TValue, we require a name, and stick it in the dictionary. Then, when the dictionary should be disposed, it disposes all of the TValue implementations that are IDisposable.
I could envision it looking something like the following:
Behind the scenes, this would either create or update a dictionary that had a mapping of names to services that was managed by the Microsoft service provider. When the dictionary would be disposed in accordance to its scope, it disposes its values.
The text was updated successfully, but these errors were encountered:
One of the major qualms I have had with the Microsoft dependency injection implementation is that it has a one-type / one-registration policy. If I have two implementations of
IFoo
, I cannot register them both simultaneously. Instead, I need to recreate them every time I need them.StructureMap, because it is not terrible, uses the concept of "named" registrations to get around this problem. When you register an implementation of a service to an interface, you can "name" that registration with a string.
We could add this functionality to the Microsoft implementation by creating some kind of disposable dictionary of type
IDictionary<string, TValue>
. For each registration ofTValue
, we require a name, and stick it in the dictionary. Then, when the dictionary should be disposed, it disposes all of theTValue
implementations that areIDisposable
.I could envision it looking something like the following:
Behind the scenes, this would either create or update a dictionary that had a mapping of names to services that was managed by the Microsoft service provider. When the dictionary would be disposed in accordance to its scope, it disposes its values.
The text was updated successfully, but these errors were encountered: