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
The native Microsoft ServiceProvider doesn't allow a registration of a singleton open generic type to be an instance that can be provided "externally". So when the child container backed by ServiceProvider is built, and the ServiceDescriptors from the parent are examined, I'll by default throw an exception when these are encountered. You can pass in an additional enum to specify how you want these services to be dealt with:
public enum ParentSingletonOpenGenericRegistrationsBehaviour
{
/// <summary>
/// If there are singleton open generic registerations in the parent container then an exception will be thrown when creating the child container. This is because there is currnetly no way to have the child container resolve the same instance of those as when resolved through the parent container. From the exception you can see a list of these unsupported registrations and then work out how to handle them.
/// </summary>
ThrowNotSupportedException = 0,
/// <summary>
/// If there are singleton open generic registerations in the parent container, they will also be registered again in the child container as seperate singletons. This means resolving an open generic type with the same type parameters in the parent and child container will yield two seperate instances of that service.
/// </summary>
DuplicateSingletons = 1,
/// <summary>
/// If there are singleton open generic registerations in the parent container, they will be omitted from the child container. In other words you'll have to register them into the child container yourself otherwise they will fail to resolve from the child container.
/// </summary>
Omit = 2
}
There might be a solution for this in future, mostly depending on the outcome of issue: dotnet/runtime#41050
The text was updated successfully, but these errors were encountered:
The native Microsoft
ServiceProvider
doesn't allow a registration of a singleton open generic type to be an instance that can be provided "externally". So when the child container backed byServiceProvider
is built, and theServiceDescriptors
from the parent are examined, I'll by default throw an exception when these are encountered. You can pass in an additional enum to specify how you want these services to be dealt with:There might be a solution for this in future, mostly depending on the outcome of issue: dotnet/runtime#41050
The text was updated successfully, but these errors were encountered: