首页 > 编程语言 >仓储层当前有接口 IRepository<T> 抽象类 BaseRepository<T> 业务逻辑层有抽象类 BaseBusiness<M, E> 接口 IBu

仓储层当前有接口 IRepository<T> 抽象类 BaseRepository<T> 业务逻辑层有抽象类 BaseBusiness<M, E> 接口 IBu

时间:2024-05-05 09:55:24浏览次数:22  
标签:逻辑 IBusiness IRepository class productRepository 仓储 接口 抽象类 public

以下是一个简单的C#示例,展示了如何实现不同表对应不同的业务逻辑层和不同的仓储实例:

// 仓储层
public interface IRepository<T>
{
    void Add(T entity);
    void Update(T entity);
    void Delete(T entity);
    T GetById(int id);
    // 其他仓储操作方法...
}

public abstract class BaseRepository<T> : IRepository<T>
{
    // 实现 IRepository 接口的通用方法
}

// 业务逻辑层
public interface IBusiness<M, E>
{
    void Process(M model);
    // 其他业务逻辑方法...
}

public abstract class BaseBusiness<M, E> : IBusiness<M, E>
{
    // 实现 IBusiness 接口的通用方法
}

// 具体业务逻辑类
public class ProductBusiness : BaseBusiness<ProductModel, ProductEntity>
{
    private readonly IRepository<ProductEntity> _productRepository;

    public ProductBusiness(IRepository<ProductEntity> productRepository)
    {
        _productRepository = productRepository;
    }

    public override void Process(ProductModel model)
    {
        // 实现特定的业务逻辑
        // 可以使用 _productRepository 执行数据操作
    }
}

public class CustomerBusiness : BaseBusiness<CustomerModel, CustomerEntity>
{
    private readonly IRepository<CustomerEntity> _customerRepository;

    public CustomerBusiness(IRepository<CustomerEntity> customerRepository)
    {
        _customerRepository = customerRepository;
    }

    public override void Process(CustomerModel model)
    {
        // 实现特定的业务逻辑
        // 可以使用 _customerRepository 执行数据操作
    }
}

// 模型和实体类
public class ProductModel
{
    // 产品模型的属性...
}

public class ProductEntity
{
    // 产品实体的属性...
}

public class CustomerModel
{
    // 客户模型的属性...
}

public class CustomerEntity
{
    // 客户实体的属性...
}

// 使用示例
class Program
{
    static void Main(string[] args)
    {
        // 注入不同的仓储实例到不同的业务逻辑类中
        IRepository<ProductEntity> productRepository = new ProductRepository();
        IBusiness<ProductModel, ProductEntity> productBusiness = new ProductBusiness(productRepository);

        IRepository<CustomerEntity> customerRepository = new CustomerRepository();
        IBusiness<CustomerModel, CustomerEntity> customerBusiness = new CustomerBusiness(customerRepository);

        // 使用业务逻辑类进行操作
        var productModel = new ProductModel();
        productBusiness.Process(productModel);

        var customerModel = new CustomerModel();
        customerBusiness.Process(customerModel);
    }
}

 

标签:逻辑,IBusiness,IRepository,class,productRepository,仓储,接口,抽象类,public
From: https://www.cnblogs.com/mojiejushi/p/18173237

相关文章

  • 二叉查找树的接口设计
    /***************************************************filename:BianrySearchTree.c*author:[email protected]*date:2024/05/04*brief:二叉查找树的接口设计*note:None**CopyRight(c)[email protected]......
  • 接口自动化测试框架搭建的思路
    参数替换的思路为什么替换参数:请求参数不一定全部都是写死的,有可能存在接口之间的数据依赖在Excel中写入特殊标记(如#key#),说明写了特殊标记的地方需要做替换处理读取Excel中的参数,通过正则表达式提取出来需要被替换的key,得到一个list遍历list,根据list中不同的参数,去不同的地方......
  • CMakeLists.txt --- 导入接口库(预编译库)
    以接口库的方式导入预编译库cmake_minimum_required(VERSION3.9)project(test)set(CMAKE_BUILD_TYPEDebug)set(CMAKE_C_FLAGS"$ENV{CFLAGS}-O2-Wall-pthread")set(CMAKE_CXX_FLAGS"$ENV{CFLAGS}-O2-Wall-pthread-std=c++11-std=gnu++11")#设置mo......
  • C# 搭建一个 基于ISqlSugarClient 三层架构框架 涉及数据库仓储 然后中间又有业务逻辑
    要在C#中搭建基于ISqlSugarClient的三层架构框架,你需要定义数据访问层(DAL)、业务逻辑层(BLL)和表现层(UI)。下面是一个完整的例子,涉及数据库仓储、业务逻辑层,以及依赖注入。这个例子基于ASP.NETCoreMVC构建,使用ISqlSugarClient来处理数据访问。这个例子中,我们将使用User作为一个简单......
  • Alpha冲刺接口文档
    Alpha冲刺用户模块POST注册POST/user/register用户在注册时需要设定好:用户名、用户密码、用户的邮箱、邮箱验证码绑定邮箱不是输入邮箱就可以了,而是要发送验证码到指定的邮箱中,确认完验证码之后才能绑定发送邮箱验证码会单独提供一个接口。逻辑可以参照,以下序列图sequen......
  • 15.Petclinic搜索接口测试执行-postman
    因 https://spring-petclinic-rest.k8s.hogwarts.ceshiren.com/petclinic/api/owners?lastName=LASTNAME接口不在支持使用故事用下方接口进行接口测试一、通过抓包获取接口信息,分析入参及响应数据选中接口鼠标右键选择:保存har导入postman二、根据接口和开发产品确认入参......
  • simpread-课程 28:API 接口请求日志【后端】
    1、添加审核日志实体1.1实体定义在项目Electric.Entity,添加文件夹:AuditLogs,并添加类:EleAuditLog。EleAuditLog完整代码如下:namespaceElectric.Entity.AuditLogs;///<summary>///审核日志///</summary>[Index(nameof(AuditLogType))]publicclassEleAuditLog:E......
  • idea在类和接口上面自动生成注释
    详细教程:https://www.cnblogs.com/ya-qiang/p/9462766.html1、File>>Settings…>>Editor>>FileandCodeTemplates/***@Auther:Zxd*@Date:${YEAR}/${MONTH}/${DAY}${TIME}*@Description:*/  ......
  • RESTful风格接口设计
    我们平常开发一般只使用GET、POST方法。而对于HTTP给出的PUT、DELETE等其他方法都没使用。以RESTful风格设计接口就能全部用上这些方法。按照RESTful理查德森成熟度模型改造接口这个模型跟数据库范式等级相似,都是一层一层满足。我们的mvc接口不好说是哪一级,一般都是每个操作一个......
  • 双向链表及双向循环链表接口设计
    双向链表及双向循环链表接口设计双向链表接口设计由于带头结点更加方便用户进行数据访问,所以本次创建一条带头结点的双向不循环的链表。创建新的头结点和新节点//数据类型typedefintdatatype_t;//创建结点类型typedefstructdoublelinckelist{datatype_tdata;......