0
Я использую шаблон репозитория мой класс DataContext выглядит следующим образом,Generic Repository не разрешаются с помощью Unity
public class DataContext : DbContext
{
public DataContext()
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Customer>().ToTable("Customer");
modelBuilder.Entity<Orders>().ToTable("Orders");
}
public IDbSet<T> DBSet<T>() where T : class
{
return this.Set<T>();
}
}
Я использую общий репозиторий следующим образом,
public interface IRepository<T> : IDisposable
{
IQueryable<T> FindAll();
T FindById(int id);
int Add(T TEntity);
int Update(T TEntity);
int Delete(T TEntity);
int Commit();
}
Реализация есть
public class SqlRepository<T> : IRepository<T> where T : class
{
private DataContext _context;
private readonly IDbSet<T> _dbSet;
bool disposing;
public SqlRepository()
{
_context = new DataContext();
_dbSet = _context.DBSet<T>();
}
public IQueryable<T> FindAll()
{
return _dbSet;
}
public T FindById(int id)
{
return _dbSet.Find(id);
}
Я использую контейнер на основе конфигурации, как,
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="CustomerManagementAPI.Data"/>
<namespace name="CustomerManagementAPI.Data"/>
<container>
<register type="IRepository" mapTo="SqlRepository">
<lifetime type="singleton"/>
</register>
<register type="ICustomerService" mapTo="CustomerService">
<lifetime type="singleton"/>
</register>
</container>
</unity>
при попытке создать экземпляр контроллера с параметрами. Я получаю следующую ошибку. Невозможно разрешить имя типа или псевдоним IRepository. Проверьте конфигурационный файл и проверьте его имя.