我有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();