泛型接口
public interface IRepository<T> where T : class, new() { T Create(); }
泛型实现
public abstract class RepositoryBase<T> : IRepository<T> where T : class,new() { public DbContext context =new CMSEntities(); public RepositoryBase() { this.context = new CMSEntities(); } //提供IOC注入方式接口 public RepositoryBase(CMSEntities context) { this.context = context; } #region IRepository<T> 成员 public T Create() { return context.Set<T>().Create(); } #endregion }
其他的接口
public interface ILink : IRepository<dt_link> { }
对应的实现:
public class LinkLogic : RepositoryBase<dt_link>, ILink { }
Unity的配置节点
<unity> <containers> <container> <types> <!--常用操作--> <type name="LinkLogic" type="CMS.Bussiness.Interface.ILink, CMS.Bussiness.Interface" mapTo="CMS.Bussiness.Logic.LinkLogic, CMS.Bussiness.Logic"/> </types> </container> </containers> </unity>
报错了
求大神帮解决啊 首次用Unity 配置就报错
<container>
<register name="LinkLogic" type="ILink" mapTo="LinkLogic"/>
</container>
还是不行 报同样的错误