仓储层当前有接口 IRepository<T> 抽象类 BaseRepository<T> 业务逻辑层有抽象类 BaseBusiness<M, E> 接口 IBusiness<M, E> 请用C# 给出一个案例,支持不同表对应不同的业务逻辑层,然后不同仓储实例。
以下是一个简单的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# 给出一个案例,支持不同表对应不同的业务逻辑层,然后不同仓储实例。的更多相关文章
- 点击文字弹出一个DIV层窗口代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 2019-8-31-C#-如何写出一个不能被其他程序集继承的抽象类
title author date CreateTime categories C# 如何写出一个不能被其他程序集继承的抽象类 lindexi 2019-08-31 16:55:58 +0800 20 ...
- C# 如何写出一个不能被其他程序集继承的抽象类
我需要限定某个抽象类只能在我程序集类实现,而不支持其他程序集实现,也就是我需要一个不能被继承的抽象类 在 C# 里面有抽象类和接口,这两个都是期望被继承才能被使用,而抽象类是可以做到只能在自己程序集和 ...
- SQL学习笔记四(补充-1-1)之MySQL单表查询补充部分:SQL逻辑查询语句执行顺序
阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SELECT语句关键字的定义顺序 SELE ...
- 根据juery CSS点击一个标签弹出一个遮罩层的简单示例
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-005action层
1. <?xml version="1.0" encoding="UTF-8" ?><!-- XML声明 --> <!DOCTYP ...
- 点击按钮弹出一个div层
JQuery弹出层,点击按钮后弹出遮罩层,还有关闭按钮 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml& ...
- cocos2d-x JS 弹出对话框触摸监听(吞噬点击事件遮挡层)
在游戏中,我们经常会碰到一些弹窗,这些弹窗禁止点透,也就是禁止触摸事件传递到底层,我们称之为遮挡层,这些遮挡层,需要开发遮挡层,我们首先得了解cocos2d-js的触摸传递机制. 根据官方文档,我们可 ...
- 案例48-crm练习利用spring管理service和dao层的对象
1 导包 2 将 Service 对象以及 Dao 对象配置到 spring 容器 <?xml version="1.0" encoding="UTF-8" ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-007View层
0.login.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
随机推荐
- 【信号与系统】求使系统稳定的常数K的范围
- 【网站搭建】开源社区Flarum搭建记录
环境 服务器系统:腾讯云 OpenCloudOS 宝塔版本:免费版8.0.1 Nginx:1.24.0 MySQL:5.7.42 PHP:8.1.21 萌狼蓝天 2023年8月7日 PHP设置 1.安 ...
- 【前端】【H5 API】实现全屏显示功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Qt编写地图综合应用51-离线瓦片地图下载
一.前言 写这个离线地图下载器的初衷,就是为了方便自己的几个需要离线地图的程序,客户需求,既然地图程序已经可以支持离线地图,那如何获取到这些离线瓦片地图文件是个关键,而且这是这个功能的关键,拿到这些一 ...
- Qt编写安防视频监控系统68-兼容Qt4到Qt6
一.前言 为了从Qt4.7兼容到Qt6.2及后续版本,着实花了不少精力,前提也是对自定义控件大全和各种跨平台的轮子组件全部做成了兼容Qt4到Qt6,这样只剩下UI这块需要兼容就好办多了,各个击破战略, ...
- 内存吞金兽(Elasticsearch)的那些事儿 -- 写入&检索原理
系列目录 内存吞金兽(Elasticsearch)的那些事儿 -- 认识一下 内存吞金兽(Elasticsearch)的那些事儿 -- 数据结构及巧妙算法 内存吞金兽(Elasticsearch)的那 ...
- Solution Set - “让朝阳洒向晚霞,在星空下涂鸦”
目录 0.「UR #12」「UOJ #182」a^-1 + b problem 1.「NOI Simu.」点 2.「集训队互测 2023」「QOJ #5100」卡牌游戏 3.「NOI Simu.」简单 ...
- 1011. 在 D 天内送达包裹的能力
在 D 天内送达包裹的能力 传送带上的包裹必须在 days 天内从一个港口运送到另一个港口. 传送带上的第 i 个包裹的重量为 weights[i].每一天,我们都会按给出重量(weights)的顺序 ...
- c#利用异步方法去模拟多线程处理业务
一个巧妙的设计 原理:利用async 标识方法执行异步处理 List<long> listIds = new List<long>();//业务任务:假设处理这个列表的任务 o ...
- w3cschool-Struts2 概述
Struts2 概述 Struts2 是目前较为普及和成熟的基于MVC设计模式的web应用程序框架,它不仅仅是Struts1 的升级版本,更是一个全新的Struts架构.最初,是以WebWork框架和 ...