简体   繁体   English

将接口扩展到基本抽象 class

[英]Having interfaces extend to base abstract class

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?或者更好的方法来 go 关于这个?

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>
    {
    }

An interface cannot inherit from a class.接口不能从 class 继承。 Here BaseService<T> is defined as a class.这里BaseService<T>被定义为 class。

A way to fix it is to declare the service as a class, as follow:修复它的一种方法是将服务声明为 class,如下所示:

public class TestService : BaseService<Test>
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM