Reputation: 13
I have a generic abstract base class with a service reference. When I try to access any properties form the concrete implementation class I receive the following error. 'Repository' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Repository' could be found (are you missing a using directive or an assembly reference?)
**Base class**
namespace Services
{
public abstract class BaseRepository<T> : IRepository<T>
{
public IService<T> _serviceContext;
public BaseRepository(IService<T> serviceContext)
{
_serviceContext = serviceContext;
}
#region IRepository<T> Members
public List<T> GetAll()
{
return _serviceContext.GetAll();
}
public T GetById(Guid id)
{
throw new NotImplementedException();
}
public void Add(T entity)
{
_serviceContext.Add(entity);
}
public void Remove(T entity)
{
throw new NotImplementedException();
}
#endregion
}
}
**Concrete class**
namespace Services
{
public class SpecialRepository : BaseRepository<SpecialItem>, ISpecialRepository
{
public SpecialRepository() : base(new DataAccess.SpecialList())
{
}
}
}
**Service Class**
namespace DataAccess
{
public class SpecialList : IService<SpecialItem>
{
public List<SpecialItem> GetAll()
{
//Implementation
}
}
}
**Repository Interface**
namespace Domain
{
public interface IRepository<T>
{
List<T> GetAll();
T GetById(Guid id);
void Add(T entity);
void Remove(T entity);
}
}
**Service Interface**
namespace DataAccess
{
public interface IService<T>
{
List<T> GetAll();
void Add(T entity);
}
}
Any help is appreciated. Thanks in advance!
Upvotes: 1
Views: 195
Reputation: 1547
You need to define an Add method in SpecialList.
I added one and I did not get an error calling
SpecialRepository rep = new SpecialRepository();
rep.Add(new SpecialItem());
Upvotes: 0