我有一个接口,并希望在其中包含一个具有参数约束的类的方法。是否有可能以这种方式创建它,以至于不需要在界面删除中包含约束条件?接口方法和参数约束
public interface IPlugin
{
void InitializeSession(MBROContext context, Reporter<TEntity, TContext> reporter);
}
TEntity是从IEntity继承的类。 TContext是从IDbcontext继承的DbContext。
对于记者类的签名如下:
public class Reporter<TEntity, TContext> where TEntity : class, IEntity where TContext : IDbContext, IDisposable, new()
{
private IUnitOfWork uow;
private IRepository<TEntity> entryRepository;
private IService<TEntity> entryService;
public Reporter()
{
this.uow = new UnitOfWork<TContext>();
this.entryRepository = uow.GetRepository<TEntity>();
this.entryService = new Service<TEntity>(this.uow);
}
public void Dispose()
{
throw new NotImplementedException();
}
}
我希望这是有道理的。
这正是我的答案建议你做的... – Servy
这就是为什么我做到了:-P –