У меня есть класс UnitofWork и он реализует IUnitOfWork. Я пытаюсь зарегистрировать это с помощью autofac:
var builder = new ContainerBuilder();
builder
.RegisterGeneric(typeof(UnitOfWork<Repository<>,>))
.As(typeof(IUnitOfWork))
.InstancePerDependency();
Реализация:
public class UnitOfWork<T, O> : IUnitOfWork
where T : Repository<O>
where O : BaseEntity
{
}
public interface IUnitOfWork : IDisposable
{
void SaveChanges();
}
Дает ошибку "Ожидаемый тип"
но эта работа работает над другим проектом:
public class Repository<T> : GenericRepository<T>
where T : BaseEntity
{
public Repository(IDbContext context)
: base(context) { }
}
public abstract class GenericRepository<T>
: IRepository<T>, IQueryable<T> where T : BaseEntity
{
}
builder
.RegisterGeneric(typeof(Repository<>))
.As(typeof(IRepository<>))
.InstancePerHttpRequest();