I am currently attempting to remove a number of .Resolve(s) in our code. I was moving along fine until I ran into a named registration and I have not been able to get Autofac resolve using the name. What am I missing to get the named registration injected into the constructor.
Registration
builder.RegisterType<CentralDataSessionFactory>().Named<IDataSessionFactory>("central").SingleInstance();
builder.RegisterType<ClientDataSessionFactory>().Named<IDataSessionFactory>("client").SingleInstance();
builder.RegisterType<CentralUnitOfWork>().As<ICentralUnitOfWork>().InstancePerDependency();
builder.RegisterType<ClientUnitOfWork>().As<IClientUnitOfWork>().InstancePerDependency();
Current class
public class CentralUnitOfWork : UnitOfWork, ICentralUnitOfWork
{
protected override ISession CreateSession()
{
return IoCHelper.Resolve<IDataSessionFactory>("central").CreateSession();
}
}
Would Like to Have
public class CentralUnitOfWork : UnitOfWork, ICentralUnitOfWork
{
private readonly IDataSessionFactory _factory;
public CentralUnitOfWork(IDataSessionFactory factory)
{
_factory = factory;
}
protected override ISession CreateSession()
{
return _factory.CreateSession();
}
}