Reputation: 2664
Using code below:
public IGenericRepository<TEntity> Repository<TEntity>() where TEntity : class
{
if (repositories.Keys.Contains(typeof(TEntity)) == true)
{
return repositories[typeof(TEntity)] as IGenericRepository<TEntity>;
}
IGenericRepository<TEntity> repo = new GenericRepository<TEntity>(_context);
repositories.Add(typeof(TEntity), repo);
return repo;
}
The Error I got,
Error 1 Inconsistent accessibility: return type 'DataModel.GenericRepository.IGenericRepository' is less accessible than method 'DataModel.UnitOfWork.UnitOfWork.Repository()' C:\Users\Anoop.k\documents\visual studio 2013\Projects\WebAPI\DataModel\UnitOfWork\UnitOfWork.cs 30 44 DataModel
I know that IGenericRepository repo is private by default. But in this sort of situation what to do? Please help me.
Upvotes: 0
Views: 491
Reputation:
I think you should define your Interface as public.
Or try this:
public IGenericRepository<TEntity> Repository<TEntity>() where TEntity : class
{
if (repositories.Keys.Contains(typeof(TEntity)) == true)
{
return repositories[typeof(TEntity)] as IGenericRepository<TEntity>;
}
GenericRepository<TEntity> repo = new GenericRepository<TEntity>(_context);
repositories.Add(typeof(TEntity), repo);
return repo;
}
Upvotes: 3
Reputation: 29243
You can't return a private type from a public method.
Change the accessibility of the IGenericRepository
to public if you want other classes to be able to use it.
See also What is a private interface?
Upvotes: 1