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