以下是一个简单的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);
}
}

仓储层当前有接口 IRepository<T> 抽象类 BaseRepository<T> 业务逻辑层有抽象类 BaseBusiness<M, E> 接口 IBusiness<M, E> 请用C# 给出一个案例,支持不同表对应不同的业务逻辑层,然后不同仓储实例。的更多相关文章

  1. 点击文字弹出一个DIV层窗口代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  2. 2019-8-31-C#-如何写出一个不能被其他程序集继承的抽象类

    title author date CreateTime categories C# 如何写出一个不能被其他程序集继承的抽象类 lindexi 2019-08-31 16:55:58 +0800 20 ...

  3. C# 如何写出一个不能被其他程序集继承的抽象类

    我需要限定某个抽象类只能在我程序集类实现,而不支持其他程序集实现,也就是我需要一个不能被继承的抽象类 在 C# 里面有抽象类和接口,这两个都是期望被继承才能被使用,而抽象类是可以做到只能在自己程序集和 ...

  4. SQL学习笔记四(补充-1-1)之MySQL单表查询补充部分:SQL逻辑查询语句执行顺序

    阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SELECT语句关键字的定义顺序 SELE ...

  5. 根据juery CSS点击一个标签弹出一个遮罩层的简单示例

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  6. JavaWeb项目开发案例精粹-第3章在线考试系统-005action层

    1. <?xml version="1.0" encoding="UTF-8" ?><!-- XML声明 --> <!DOCTYP ...

  7. 点击按钮弹出一个div层

    JQuery弹出层,点击按钮后弹出遮罩层,还有关闭按钮 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml& ...

  8. cocos2d-x JS 弹出对话框触摸监听(吞噬点击事件遮挡层)

    在游戏中,我们经常会碰到一些弹窗,这些弹窗禁止点透,也就是禁止触摸事件传递到底层,我们称之为遮挡层,这些遮挡层,需要开发遮挡层,我们首先得了解cocos2d-js的触摸传递机制. 根据官方文档,我们可 ...

  9. 案例48-crm练习利用spring管理service和dao层的对象

    1 导包 2 将 Service 对象以及 Dao 对象配置到 spring 容器 <?xml version="1.0" encoding="UTF-8" ...

  10. JavaWeb项目开发案例精粹-第3章在线考试系统-007View层

    0.login.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

随机推荐

  1. 【Python】【图像处理】图片压缩方法

    一直想找个"无损压缩"的办法. 当然这并非真的无损. 我采用了Opencv的处理图像相关的方法. 请见代码: 注意: opencv安装:pip install opencv-pyt ...

  2. Macos 安装md5sum、sha1sum、md5deep、sha1deep

    一.安装md5sum和sha1sum 方法一:brew 安装 # brew install md5sha1sum 方法二:编译安装 源码下载地址:http://www.microbrew.org/to ...

  3. TheScope, Visibility and Lifetime of Variables

    C language-- TheScope, Visibility and Lifetime of Variables 全局变量 普通全局变量 //file1 #include<stdio.h& ...

  4. Qt编写物联网管理平台49-设备模拟工具

    一.前言 本系统专门配备了设备模拟工具,用来在没有外接真实设备的时候,模拟modbus协议数据,支持多个设备,支持串口和网络方式,可切换正常数据和报警数据,反应到主程序上.对应主程序中两种端口,一种是 ...

  5. POST、GET、@RequestBody和@RequestParam区别

    参考链接: 1.POST.GET.@RequestBody和@RequestParam区别 2.@RequestBody的使用

  6. 一套分布式IM即时通讯系统的技术选型和架构设计

    本文由冰河分享,作者博客 binghe.gitcode.host,原题"这套分布式IM即时通讯系统如何写到简历上?我给你整理好了!",本文有修订和改动. 1.引言 分布式IM即时通 ...

  7. 基于开源IM即时通讯框架MobileIMSDK:RainbowChat v8.4版已发布

    关于MobileIMSDK MobileIMSDK 是一套专门为移动端开发的开源IM即时通讯框架,超轻量级.高度提炼,一套API优雅支持UDP .TCP .WebSocket 三种协议,支持iOS.A ...

  8. macOS安装编译pcl

    macOS安装编译pcl git clone git@github.com:PointCloudLibrary/pcl.git cd pcl brew install eigen brew insta ...

  9. Solution Set - 多项式杂题

    0. 「OurOJ #46942」/「51nod #1824」染色游戏   Private link & Submission.   首先,显然有 \[f(t)=\sum_{i=0}^t\bi ...

  10. 基于Qt的OFD阅读器开发原理与实践

    摘要 本文详细探讨了基于Qt开发OFD阅读器的原理与实践.通过解析OFD文件格式.构建文档结构.实现页面渲染.处理用户交互以及进行性能优化,本文展示了如何使用Qt框架开发一个功能强大.性能优异的OFD ...