0

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.

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
SharmaPattar
  • 2,472
  • 3
  • 21
  • 23

2 Answers2

3

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;
}
  • Ah, now I see it. It might be a good idea, then, to point out where it's different. – Rik Oct 14 '15 at 10:56
1

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?

Community
  • 1
  • 1
Rik
  • 28,507
  • 14
  • 48
  • 67