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
This approach, however, contains the following downsides:
Because the dependency injection behavior consists of argument verification, which gets triggered for every made registration, this behavior needs to be set very early in the pipeline, before any registrations are made.
The creation of a new implementation is cumbersome, for the default use case.
The default use case for adding a new behavior is the following:
Only the GetInstanceProducer needs to be implemented, where the Verify just forwards to the wrapped (or original) IDependencyInjectionBehavior implementation.
The new behavior almost never completely replaces the original behavior, but rather is an append model, where the behavior returns InstanceProducer instances for a sub set of dependencies.
I'm currently looking at simplifying integration with .NET Core and making it easier to integrate Microsoft's ILogger into Simple Injector (much as described here). Integration with ILogger, however, means the creation of a custom IDependencyInjectionBehavior, for instance using a custom AddLogging() extension method. The order in which a user calls AddLogging(), unfortunately, is not very undeterministic. Although we could throw a descriptive exception explaining the user to call AddLogging sooner, this still might cause problems as registrations might have been added already to the container, rendering the AddLogging extension useless.
With respect to this use case, I like to allow "verification-less injection behaviors" to be added to the container even after registrations are made, up to the point that the container is locked.
I, therefore, suggest the addition of a helper method on ContainerOptions that simplifies this use case, and allows the previous downsides to be fixed:
// Method on ContainerOptions// Calling this method multiple times works as a decorator. When the delegate returns null// the previously added delegate will be called.publicvoidAddDependencyInjectionBehavior(Func<InjectionConsumerInfo,InstanceProducer?>extension);
When AddDependencyInjectionBehavior is called multiple times with new IDependencyInjectionBehavior implementations being hooked as well, in which order should they be executed? (e.g. should each call to AddDependencyInjectionBehavior result in a new IDependencyInjectionBehavior implementation replacing the original one?)
Should the addition of a full IDependencyInjectionBehavior implementation (i.e. calling Options.DependencyInjectionBehavior) be able to replace all AddDependencyInjectionBehavior delegates by not calling the wrapped implementation?
The text was updated successfully, but these errors were encountered:
Simple Injector allows its dependency injection behavior to be altered by the use of the
IDependencyInjectionBehavior
interface, e.g.:This approach, however, contains the following downsides:
The default use case for adding a new behavior is the following:
GetInstanceProducer
needs to be implemented, where theVerify
just forwards to the wrapped (or original)IDependencyInjectionBehavior
implementation.InstanceProducer
instances for a sub set of dependencies.I'm currently looking at simplifying integration with .NET Core and making it easier to integrate Microsoft's
ILogger
into Simple Injector (much as described here). Integration withILogger
, however, means the creation of a customIDependencyInjectionBehavior
, for instance using a customAddLogging()
extension method. The order in which a user callsAddLogging()
, unfortunately, is not very undeterministic. Although we could throw a descriptive exception explaining the user to callAddLogging
sooner, this still might cause problems as registrations might have been added already to the container, rendering theAddLogging
extension useless.With respect to this use case, I like to allow "verification-less injection behaviors" to be added to the container even after registrations are made, up to the point that the container is locked.
I, therefore, suggest the addition of a helper method on
ContainerOptions
that simplifies this use case, and allows the previous downsides to be fixed:With the following usage:
Open questions:
AddDependencyInjectionBehavior
is called multiple times with newIDependencyInjectionBehavior
implementations being hooked as well, in which order should they be executed? (e.g. should each call toAddDependencyInjectionBehavior
result in a newIDependencyInjectionBehavior
implementation replacing the original one?)IDependencyInjectionBehavior
implementation (i.e. callingOptions.DependencyInjectionBehavior
) be able to replace allAddDependencyInjectionBehavior
delegates by not calling the wrapped implementation?The text was updated successfully, but these errors were encountered: