I was using Unity DI Container v5.8.4 on my .NET Core 2.1 project and I needed to register Mediator
object and I was using the configuration suggested here.
Now I have updated to v5.9.4 and I have an error about RegisterType
method arguments:
Cannot convert from 'Unity.Lifetime.LifetimeManager' to 'Unity.Injection.InjectionMember'
This is my actual code:
public static IUnityContainer RegisterMediator(this IUnityContainer container, LifetimeManager lifetimeManager)
{
return container.RegisterType<IMediator, Mediator>(lifetimeManager)
.RegisterInstance<ServiceFactory>(type =>
{
var enumerableType = type
.GetInterfaces()
.Concat(new[] { type })
.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));
return enumerableType != null
? container.ResolveAll(enumerableType.GetGenericArguments()[0])
: container.IsRegistered(type)
? container.Resolve(type)
: null;
});
}
What have I to do to update the registration code?
They have changed the signature of the RegisterType
in this PR and it is now taking a ITypeLifetimeManager
instead of a LifetimeManager
.
The HierarchicalLifetimeManager
is now implementing the ITypeLifetimeManager
interface so you just need to update the lifetimeManager
parameter in your RegisterMediator
method:
public static IUnityContainer RegisterMediator(this IUnityContainer container,
ITypeLifetimeManager lifetimeManager)
{
return container.RegisterType<IMediator, Mediator>(lifetimeManager)
...
}