I'm having difficulties in understanding how Unity resolves references for objects further down the hierarchy tree and how to inject the relevant constructors.
Currently I have my container configured thus:
container
.RegisterType<IDataContextAsync, Zeus>("ZeusLive", new PerRequestLifetimeManager(), new InjectionConstructor("ZeusLive"))
.RegisterType<IDataContextAsync, Zeus>("Zeus", new PerRequestLifetimeManager(), new InjectionConstructor("Zeus"))
.RegisterType<IUnitOfWorkAsync, UnitOfWork>("ZeusUnitOfWork", new InjectionConstructor(new ResolvedParameter<IDataContextAsync>("Zeus")))
.RegisterType<IRepositoryAsync<cd_Job>, Repository<cd_Job>>(new InjectionConstructor(new ResolvedParameter<IUnitOfWorkAsync>("ZeusUnitOfWork"), new ResolvedParameter<IDataContextAsync>("Zeus")));
(I'm using a generic Unit of work and Repository pattern (https://genericunitofworkandrepositories.codeplex.com/))
The issue is with this line:
.RegisterType<IRepositoryAsync<cd_Job>, Repository<cd_Job>>(new InjectionConstructor(new ResolvedParameter<IUnitOfWorkAsync>("ZeusUnitOfWork"), new ResolvedParameter<IDataContextAsync>("Zeus")))
I get the following error:
The type Repository.Pattern.Ef6.Repository`1[[DataRepository.Models.cd_Job, DataRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] does not have a constructor that takes the parameters (IUnitOfWorkAsync, IDataContextAsync)
Where the constructor for the Repository class is as follows:
public Repository(IDataContextAsync context, IUnitOfWorkAsync unitOfWork)
{
_context = context;
_unitOfWork = unitOfWork;
// Temporarily for FakeDbContext, Unit Test and Fakes
var dbContext = context as DbContext;
if (dbContext != null)
{
_dbSet = dbContext.Set<TEntity>();
}
else
{
var fakeContext = context as FakeDbContext;
if (fakeContext != null)
{
_dbSet = fakeContext.Set<TEntity>();
}
}
}
I suspect my issue is that I don't fully understand how the hierarchical references are resolved and my mistake is obvious, but I'm still learning so would appreciate some pointers