仓储层当前有接口 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=" ...
随机推荐
- 《刚刚问世》系列初窥篇-Java+Playwright自动化测试-8- 元素高级定位技巧(详细教程)
1.简介 随着网页的复杂性和动态性的增加,自动化测试变得越来越重要.Playwright作为一款强大的无头浏览器测试库,提供了多种元素定位方式,使得我们能够轻松地对网页进行自动化操作.在基础的定位方式 ...
- 我们需要什么样的 ORM 框架
了解我的人都知道, 本人一直非常排斥 ORM 框架, 由于对象关系阻抗不匹配, 一直觉得它没有什么用, 操作数据库最好的手段是 sql+动态语言. 但这两年想法有了重大改变. 2013 年用 js 实 ...
- 基于Java SpringBoot的音乐网站与分享平台
@ 目录 摘要 1. 研究背景 2.研究内容 3.系统功能 3.1前台首页功能模块 3.2在线听歌功能模块 3.3后台登录功能模块 3.4在线听歌管理模块 4.部分功能代码实现 5.源码分享(免费获取 ...
- [转]Error: Node Sass does not yet support your current environment: Windows 64-bit
错误日志:Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported ...
- IntelliJ IDEA打开Spring Booot项目并使用Maven导入依赖包时提示错误:Cannot resolve com.gexin.platform:gexin-rp-sdk-http:4.1.0.5
构建项目时报错: Cannot resolve com.gexin.platform:gexin-rp-sdk-http:4.1.1.4 gexin-rp-sdk-http:jar:4.1.1.4总 ...
- COCI 2024/2025 #3
T1 P11474 [COCI 2024/2025 #3] 公交车 / Autobus 愤怒,从红升橙足以说明其恶心,考场上调了半小时才过. 这道题的车能够开 \(24\) 小时,并且他能从前一天开到 ...
- 在Quartz .NET的工作类中使用依赖注入
Quartz .NET默认的Execute方法是不支持非空的构造函数的,所以.net core常用的构造函数依赖注入也搞不来,网上搜索一番搞定了这个问题. 解决方案简单来说就是自定义一个任务工厂,替换 ...
- Linux环境python3-pip安装指定源地址
# 新建配置文件 vim ~/.pip/pip.conf # 写入地址 [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [i ...
- 循序渐进--从零开始建设k8s监控之alertmanager+发送飞书(三)
前言 书接上文,prometheus已经安装好了,监控数据是有了,我们需要对其进行告警,并且可以发送到对应的平台,比如飞书.钉钉等,这里选择用飞书来测试 环境准备 组件 版本 操作系统 Ubuntu ...
- HTTP劫持
HTTP劫持 想了解什么是HTTPS,要先知道什么是HTTP HTTP HTTP是一个基于TCP/IP通信协议来传递数据的协议,传输的数据类型为HTML文件,图片文件,查询结果等,一般基于B/S架构, ...