以下是一个简单的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. JDK 18 最新动态和 JDK 19 新特性预测

    JDK 18 最新动态和 JDK 19 新特性预测_语言 & 开发_Michael Redlich_InfoQ精选文章 里面提到文章 定界延续(delimited continuations) ...

  2. 龙哥量化:通达信(KT交易师)分时图主图叠加5分钟K线图

    股友要求在通达信分时图主图叠加5分钟K线,但是通达信的分时图取不到最高价,最低价等数据,限制非常多. 然后我在KT交易师上写的公式测试成功了,效果如下. 如果您需要公式源码或者代写公式, 请联系我. ...

  3. Qt编写安防视频监控系统51-功能激活

    一.前言 随着视频监控系统本身功能的增多,以及用户定制功能的增多(比如视频监控系统摇身一变成了机器人监控.无人机监控.挖掘机监控等),除了提供工作模式这个切换开关,还需要对不同的工作模式启用禁用不同的 ...

  4. Qt开源作品25-电池电量控件

    一.前言 现在这个时代,智能手机不要太流行,满大街都是,甚至连爷爷奶奶级别的人都会用智能手机,本次要写的控件就是智能手机中的电池电量表示控件,采用纯painter绘制,其实也可以采用贴图,我估计大部分 ...

  5. 将maven项目打包上传到私服

    1. 配置私服账户密码 在maven 的setting.xml 中配置用户名和密码: <servers> <server> <username>deployment ...

  6. Wasm在即时通讯IM场景下的Web端应用性能提升初探

    本文由得物技术WWQ分享,原题"基于IM场景下的Wasm初探:提升Web应用性能",下文进行了排版和内容优化. 1.什么是Wasm Wasm,全称 WebAssembly,官网描述 ...

  7. OpenMMLab AI实战营 第一课笔记

    OpenMMLab AI实战营 第一课笔记 OpenMMLab AI实战营第一节课由子豪兄讲解,课程主要内容主要围绕计算机视觉和OpenMMLab开源算法体系以及机器学习和神经网络简介进行展开.这里要 ...

  8. DVWA靶场Insecure CAPTCHA(不安全验证)漏洞所有级别通关教程及源码审计

    Insecure CAPTCHA(不安全验证) Insecure CAPTCHA(不安全验证)漏洞指的是在实现 CAPTCHA(完全自动化公共图灵测试区分计算机和人类)机制时,未能有效保护用户输入的验 ...

  9. 记录一次线上服务OOM排查

    外面,阳光明媚,一切正好. 就在我欢天喜地准备迎来愉快的双休时,忽然之间,天塌了. 刚上线一小时的服务内存异常OOM了! 老实说,在我印象里OOM问题只存在于网上案例中,练习编码时常两年半,还是第一次 ...

  10. git worktree同一个仓库多个分支并行开发和管理

    介绍 Git Worktree 是 Git 提供的一个功能,允许你在同一个仓库中同时工作在多个工作目录中,每个目录都有自己的工作树和索引.这对于同时处理多个分支或版本非常有用. 常用命令 命令 解释 ...