Reputation: 72
I'm trying to have a base service that has common functionality that is inherited by all other services, but am having trouble and getting the following error:
Type 'BaseService<Test>' in interface list is not an interface
Can anyone suggest a way to fix this? Or a better way to go about this?
Base Service
public class BaseService<T> where T : BaseEntity
{
private readonly Context _db;
public BaseService()
{
}
public BaseService(Context db)
{
_db = db;
}
public async Task<bool> Insert(T entity)
{
entity.ModifiedOn = DateTime.UtcNow;
await _db.Set<T>().AddAsync(entity);
try
{
return await _db.SaveChangesAsync() > 0 ? true : false;
}
catch (Exception ex)
{
return false;
}
}
}
And then a normal service that would have access to this but where the error is displaying
public interface ITestService : BaseService<Test>
{
}
Upvotes: 0
Views: 71
Reputation: 356
An interface cannot inherit from a class. Here BaseService<T>
is defined as a class.
A way to fix it is to declare the service as a class, as follow:
public class TestService : BaseService<Test>
{
}
Upvotes: 1