我有UnitofWork类,它实现了IUnitOfWork。我尝试注册与autofac:使用Autofac注册Generic类型
var builder = new ContainerBuilder();
builder
.RegisterGeneric(typeof(UnitOfWork<Repository<>,>))
.As(typeof(IUnitOfWork))
.InstancePerDependency();
实施是:
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();
:
public class UnitOfWork<T, O> : IUnitOfWork
where T : Repository<O>
where O : BaseEntity
{
}
public interface IUnitOfWork : IDisposable
{
void SaveChanges();
}
给出了一个错误“类型期待”
但在另一个项目这一个工作
“给出一个错误“预期类型”,你必须更加明确,你的意思是t C#编译器给出这个错误,对吧? – Steven 2013-03-05 15:27:59
对不起,项目无法编译并出现UnitOfWork的“Type Expected”错误 –
shortcode
2013-03-05 16:03:12