CSharp: Decorator Pattern
项目结构/* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : IBusinessFlow​.cs */ using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Threading.Tasks; namespace DecoratorPattern.Abstractions { /// summary /// /// /summary public interface IBusinessFlow { string FlowName { get; } Task ExecuteAsync(CancellationToken cancellationToken default); } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : LoggingBusinessFlowDecorator​.cs */ using DecoratorPattern.Abstractions; using Microsoft.Extensions.Logging; using System; using System.Threading; using System.Threading.Tasks; namespace DecoratorPattern.Decorators { /// summary /// /// /summary public class LoggingBusinessFlowDecorator : IBusinessFlow { private readonly IBusinessFlow _innerBusinessFlow; private readonly ILoggerLoggingBusinessFlowDecorator _logger; /// summary /// /// /summary /// param nameinnerBusinessFlow/param /// param namelogger/param /// exception crefArgumentNullException/exception public LoggingBusinessFlowDecorator( IBusinessFlow innerBusinessFlow, ILoggerLoggingBusinessFlowDecorator logger) { _innerBusinessFlow innerBusinessFlow ?? throw new ArgumentNullException(nameof(innerBusinessFlow)); _logger logger ?? throw new ArgumentNullException(nameof(logger)); } public string FlowName _innerBusinessFlow.FlowName; /// summary /// /// /summary /// param namecancellationToken/param /// returns/returns public async Task ExecuteAsync(CancellationToken cancellationToken default) { _logger.LogInformation( 【流程启动】{FlowName} , FlowName); try { await _innerBusinessFlow.ExecuteAsync(cancellationToken); _logger.LogInformation( 【流程完成】{FlowName} , FlowName); } catch (Exception ex) { _logger.LogError(ex, 【流程异常】{FlowName} 执行过程中发生未预期的异常 , FlowName); throw; } } } }/* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : BusinessFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 9.业务订单流程 /// 业务客户接单、订单录入、需求确认、订单跟进、售后对接 /// /summary public class BusinessFlow : IBusinessFlow { public string FlowName 业务订单流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.接待客户、确认定制需求 // 2.系统录入订单信息、定价核算 // 3.订单状态全程跟进 // 4.交付后售后对接登记 await Task.Delay(170, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : DesignDrawingFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 2.设计制图流程 /// 业务客户需求对接、首饰建模、CAD制图、方案审核定稿 /// /summary public class DesignDrawingFlow : IBusinessFlow { public string FlowName 设计制图流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.收集客户定制需求 // 2.首饰三维建模、CAD图纸绘制 // 3.初稿审核、客户确认 // 4.定稿归档下发生产图纸 await Task.Delay(250, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : FinanceFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 7.财务流程 /// 业务订单对账、成本核算、开票登记、回款核销、账务归档 /// /summary public class FinanceFlow : IBusinessFlow { public string FlowName 财务流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.订单金额对账 // 2.原料、人工、加工成本核算 // 3.增值税开票登记 // 4.客户回款核销、账务归档 await Task.Delay(210, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : ItFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 11.IT技术支撑流程 /// 业务业务系统维护、服务器监控、日志运维、故障排查、权限管理 /// /summary public class ItFlow : IBusinessFlow { public string FlowName IT技术支撑流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.业务系统日常巡检 // 2.服务器与数据库监控 // 3.系统权限分配与维护 // 4.运维故障记录与修复 await Task.Delay(130, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : LogisticsFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 6.物流流程 /// 业务仓储出库、物流对接、保价发货、物流轨迹录入、签收跟踪 /// /summary public class LogisticsFlow : IBusinessFlow { public string FlowName 物流流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.仓库出库核验 // 2.贵重物品保价配置 // 3.物流单生成、揽收发货 // 4.系统录入物流轨迹 await Task.Delay(180, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : MarketingPromotionFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 8.营销推广流程 /// 业务新品宣传、活动策划、线上引流、门店推广、数据统计 /// /summary public class MarketingPromotionFlow : IBusinessFlow { public string FlowName 营销推广流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.新品款式宣传素材制作 // 2.线上商城、短视频推广投放 // 3.门店促销活动落地 // 4.推广转化数据统计汇总 await Task.Delay(190, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : PackagingFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 5.包装流程 /// 业务首饰清洁、防护包装、礼盒封装、证书配套、防伪贴标 /// /summary public class PackagingFlow : IBusinessFlow { public string FlowName 包装流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.成品清洁除尘 // 2.独立防护包装 // 3.配套质检证书、售后卡 // 4.礼盒封装、粘贴防伪码 await Task.Delay(120, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : PersonnelAdminFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 10.人事行政流程 /// 业务人员考勤、排班调度、行政物资、制度落地、人员异动 /// /summary public class PersonnelAdminFlow : IBusinessFlow { public string FlowName 人事行政流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.员工考勤统计、排班调整 // 2.办公物资申领核销 // 3.日常行政巡查 // 4.人员入职、异动、离职登记 await Task.Delay(100, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : ProcessingProductionFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 3.加工生产流程 /// 业务金属浇筑、切割、镶嵌、打磨、抛光、电镀全工序 /// 模拟高并发多工序并行执行 /// /summary public class ProcessingProductionFlow : IBusinessFlow { public string FlowName 加工生产流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 多工序并行模拟工厂高并发生产场景 var tasks new ListTask { SingleProcess(金属基材浇筑成型, 150, cancellationToken), SingleProcess(宝石精密镶嵌定位, 180, cancellationToken), SingleProcess(首饰精细打磨修边, 160, cancellationToken), SingleProcess(镜面抛光真空电镀, 200, cancellationToken) }; await Task.WhenAll(tasks); } /// summary /// 单个生产工序模拟 /// /summary private async Task SingleProcess(string processName, int ms, CancellationToken ct) { await Task.Delay(ms, ct); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : QualityInspectionFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 4.质检流程 /// 业务成品尺寸校验、牢固度检测、瑕疵筛查、品级定级、出具质检报告 /// /summary public class QualityInspectionFlow : IBusinessFlow { public string FlowName 质检流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.外观瑕疵检测 // 2.宝石牢固度、金属纯度检测 // 3.尺寸参数核对 // 4.合格品定级、不合格品返修登记 await Task.Delay(220, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : RawMaterialPurchaseFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 1.原料采购核验流程 /// 业务珠宝贵金属、宝石原料采购、到货核验、证书校验、入库登记 /// /summary public class RawMaterialPurchaseFlow : IBusinessFlow { public string FlowName 原料采购核验流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.核对采购合同与到货清单 // 2.贵金属称重、宝石品级核验 // 3.质检证书真伪校验 // 4.录入供应链系统、完成原料入库 await Task.Delay(200, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : TrainingFlow​.cs */ using DecoratorPattern.Abstractions; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 12.员工培训流程 /// 业务新员工岗前培训、工艺培训、服务培训、考核归档 /// /summary public class TrainingFlow : IBusinessFlow { public string FlowName 员工培训流程; public async Task ExecuteAsync(CancellationToken cancellationToken default) { // 1.制定月度培训计划 // 2.首饰工艺、销售服务培训落地 // 3.员工技能考核 // 4.培训成绩归档存档 await Task.Delay(140, cancellationToken); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : WorkflowScheduler​.cs */ using DecoratorPattern.Abstractions; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text; namespace DecoratorPattern.Services { /// summary /// 珠宝全业务流程调度器 /// 负责按行业标准顺序执行所有业务流程、统一日志调度、异常管控、取消令牌支持 /// 线程安全、兼容高并发、适配DI生命周期 /// /summary public class WorkflowScheduler { private readonly IEnumerableIBusinessFlow _businessFlows; private readonly ILoggerWorkflowScheduler _logger; /// summary /// 构造注入有序业务流程集合 日志器 /// /summary public WorkflowScheduler(IEnumerableIBusinessFlow businessFlows, ILoggerWorkflowScheduler logger) { _businessFlows businessFlows ?? throw new ArgumentNullException(nameof(businessFlows)); _logger logger ?? throw new ArgumentNullException(nameof(logger)); } /// summary /// 启动完整珠宝行业业务链路 /// /summary /// param namecancellationToken/param /// returns/returns public async Task RunEntireWorkflowAsync(CancellationToken cancellationToken default) { _logger.LogInformation( 珠宝行业全业务流程调度启动 ); _logger.LogInformation(待执行业务流程总数{Count}, _businessFlows.Count()); var index 0; foreach (var flow in _businessFlows) { if (cancellationToken.IsCancellationRequested) { _logger.LogWarning(流程调度收到取消指令终止后续所有流程); break; } index; _logger.LogInformation(开始执行第{Index}项业务流程, index); try { await flow.ExecuteAsync(cancellationToken); } catch (Exception ex) { _logger.LogError(ex, 第{Index}项流程执行失败全流程终止, index); throw; } } _logger.LogInformation( 珠宝行业全业务流程全部执行完成 ); } } }调用/* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 装饰器模式 Decorator Pattern 演示业务层 # Author : geovindu,Geovin Du 涂聚文. # IDE : vs2026 c# .net 10 # os : windows 10 # database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j # Datetime : 2026/07/04 22:16 # User : geovindu # Product : Visual Studio 2026 # Project : CSharpDesignPattern # File : DecoratorBll.cs */ using DecoratorPattern.Abstractions; using DecoratorPattern.Decorators; using DecoratorPattern.Services; using Karambolo.Extensions.Logging.File; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; namespace BLL { /// summary /// /// /summary public class DecoratorBll { public async void Demo() { // 1.构建.NET通用主机DI、日志、生命周期托管 var host Host.CreateDefaultBuilder() .ConfigureLogging((context, loggingBuilder) { // 清空默认日志避免重复输出 loggingBuilder.ClearProviders(); // 控制台日志配置 loggingBuilder.AddConsole(options { options.IncludeScopes true; options.TimestampFormat yyyy-MM-dd HH:mm:ss.fff; }); loggingBuilder.AddFile(fileBuilder { fileBuilder.RootPath Directory.GetCurrentDirectory(); string todayDate DateTime.Now.ToString(yyyy-MM-dd); Directory.CreateDirectory(Path.Combine(fileBuilder.RootPath, Logs, todayDate)); fileBuilder.Files new[] { new LogFileOptions { Path $Logs/{todayDate}/app-debug.log, MaxFileSize 1000000, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Debug }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-info.log, MaxFileSize 1000000, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Information }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-warn.log, MaxFileSize 1000000, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Warning }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-error.log, MaxFileSize 1000000, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Error }, IncludeScopes true } }; }); // 全局日志级别控制 loggingBuilder.SetMinimumLevel(LogLevel.Debug); // 过滤系统低级日志避免刷屏 loggingBuilder.AddFilter(Microsoft, LogLevel.Warning); loggingBuilder.AddFilter(System, LogLevel.Warning); }) .ConfigureServices((context, services) { // 2.注册所有原始业务流程瞬态多线程安全 services.AddTransientRawMaterialPurchaseFlow(); services.AddTransientDesignDrawingFlow(); services.AddTransientProcessingProductionFlow(); services.AddTransientQualityInspectionFlow(); services.AddTransientPackagingFlow(); services.AddTransientLogisticsFlow(); services.AddTransientFinanceFlow(); services.AddTransientMarketingPromotionFlow(); services.AddTransientBusinessFlow(); services.AddTransientPersonnelAdminFlow(); services.AddTransientItFlow(); services.AddTransientTrainingFlow(); // 3.【装饰器模式注入】按真实珠宝业务顺序批量包装日志装饰器 // 业务正向流程采购→设计→生产→质检→包装→物流→财务→营销→业务→人事→IT→培训 services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceRawMaterialPurchaseFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceDesignDrawingFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceProcessingProductionFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceQualityInspectionFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServicePackagingFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceLogisticsFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceFinanceFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceMarketingPromotionFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceBusinessFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServicePersonnelAdminFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceItFlow(), sp)); services.AddTransientIBusinessFlow(sp WrapDecorator(sp.GetRequiredServiceTrainingFlow(), sp)); // 4.注册调度器 services.AddTransientWorkflowScheduler(); }) .Build(); // 5.执行全流程 using var scope host.Services.CreateScope(); var provider scope.ServiceProvider; var logger provider.GetRequiredServiceILoggerDecoratorBll(); try { var scheduler provider.GetRequiredServiceWorkflowScheduler(); await scheduler.RunEntireWorkflowAsync(); } catch (Exception ex) { logger.LogCritical(ex, 珠宝全业务流程调度发生致命异常); } finally { // 优雅停机刷新日志缓冲区防止日志丢失 await host.StopAsync(); } } /// summary /// 统一包装方法将任意业务流程包装为【日志装饰器流程】 /// 纯原生DI实现无第三方框架依赖 /// /summary private static IBusinessFlow WrapDecorator(IBusinessFlow flow, IServiceProvider sp) { var logger sp.GetRequiredServiceILoggerLoggingBusinessFlowDecorator(); return new LoggingBusinessFlowDecorator(flow, logger); } } }输出本项目展示了一个采用装饰器模式(Decorator Pattern)实现的珠宝行业业务流程管理系统。系统包含12个核心业务流程如原料采购、设计制图、加工生产等每个流程实现IBusinessFlow接口。通过LoggingBusinessFlowDecorator装饰器为各流程动态添加日志功能实现业务逻辑与日志记录的分离。WorkflowScheduler负责按顺序执行所有业务流程支持取消令牌和异常处理。系统采用.NET依赖注入框架结合文件日志和控制台日志实现了灵活的业务流程组合与扩展。代码结构清晰体现了装饰器模式在不修改原有类的情况下动态扩展对象功能的优势。

相关新闻

Spring Boot RESTful API测试类编写实战指南

Spring Boot RESTful API测试类编写实战指南

1. Spring Boot RESTful Demo测试类实战指南 在Java后端开发领域,Spring Boot已经成为构建现代化Web应用的事实标准。最近在帮团队新人排查一个接口问题时,发现很多开发者虽然能快速搭建RESTful服务,但对测试类的编写往往停留在表面。今天我就…

2026/9/20 8:19:15 阅读更多 →
【YOLO26多模态创新改进】全网独家复现创新 | TGRS 2025 | 引入MROD-YOLO的 MJRNet 多模态联合表征网络模块,对可见光与红外信息的早期深度融合、充分发挥多模态互补优势

【YOLO26多模态创新改进】全网独家复现创新 | TGRS 2025 | 引入MROD-YOLO的 MJRNet 多模态联合表征网络模块,对可见光与红外信息的早期深度融合、充分发挥多模态互补优势

一、本文介绍 🔥本文给大家介绍使用 MJRNet 多模态联合表征网络模块改进 YOLO26 多模态目标检测模型,其核心作用是在网络前端实现高质量的多模态联合表征学习,通过对可见光与红外信息的早期深度融合,为后续检测提供信息充分且对齐良好的输入特征。MJRNet 利用全局上下文注…

2026/9/25 4:51:21 阅读更多 →
助睿浏览器市场与用户画像分析-数据分析

助睿浏览器市场与用户画像分析-数据分析

浏览器市场与用户画像分析-数据加工1 实验目的本实验基于“用户-日-浏览器-小时”明细表,完成数据大屏所需的各项统计表加工,包括:浏览器市场格局统计(覆盖率、使用时长)浏览器周活跃趋势统计浏览器使用频率分布统计用…

2026/9/19 12:33:22 阅读更多 →

最新新闻

低功耗电压检测电路设计:MOS管如何让电池多活一年

低功耗电压检测电路设计:MOS管如何让电池多活一年

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/25 4:53:50 阅读更多 →
特斯拉HW4.0硬件深度拆解:11摄像头+4D雷达如何重塑自动驾驶感知

特斯拉HW4.0硬件深度拆解:11摄像头+4D雷达如何重塑自动驾驶感知

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/25 4:53:49 阅读更多 →
C++中^不是次方:幂运算的正确姿势与避坑指南

C++中^不是次方:幂运算的正确姿势与避坑指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/25 4:53:49 阅读更多 →
C# WinForm流程图控件源码解析:GDI+绘制、拖动与序列化全实现

C# WinForm流程图控件源码解析:GDI+绘制、拖动与序列化全实现

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/25 4:53:49 阅读更多 →
Wormhole勒索病毒深度分析:蠕虫式横向传播与应急响应实战

Wormhole勒索病毒深度分析:蠕虫式横向传播与应急响应实战

1. 一次真实的应急响应:从一台中招机器说起凌晨两点被电话叫醒,对方是合作公司的运维负责人,语气很急——财务共享盘里所有文件后缀全变了,桌面上多了一个文本文件,里面写着要联系某个邮箱、支付一笔加密货币。我让他先…

2026/9/25 4:53:49 阅读更多 →
用OpenCvSharp给USB摄像头做H264录像:FFmpeg管道绕开编码器坑

用OpenCvSharp给USB摄像头做H264录像:FFmpeg管道绕开编码器坑

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/25 4:52:48 阅读更多 →

日新闻

AI元人文:从工具使用到思维重构的深度探索

AI元人文:从工具使用到思维重构的深度探索

最近半年我一直在琢磨一件事:AI元人文到底是什么?说白了,就是“用元视角重新审视人与AI的关系”,也在“探索AI如何反向逼着我们发现自己的思考边界”。标题里的“元探索”,在我看就是一层套一层的追问——当你用AI解决…

2026/9/25 0:00:41 阅读更多 →
Python+CNN车牌识别实战:从数据预处理到模型训练与部署

Python+CNN车牌识别实战:从数据预处理到模型训练与部署

简介:基于Python与卷积神经网络的车牌识别项目,面向计算机视觉初学者及智能交通开发者,目标是帮助用户掌握从数据预处理、模型构建到实际部署的完整流程。压缩包共25个文件,包含jpg/png图像样本、py训练脚本、md说明文档、dat数据…

2026/9/25 0:00:41 阅读更多 →
Vim基础操作全攻略:保存退出、模式切换与高频命令实战

Vim基础操作全攻略:保存退出、模式切换与高频命令实战

1. 项目概述1.1 核心需求解析今天聊聊Vim。写这个题目的原因是:几乎每个后端开发者、运维人员、数据工程师某天都会遇到一个场景——深夜加班,服务器登录界面只有黑底白字,编辑器只有vi/vim,你必须在五分钟内完成一次配置修改并保…

2026/9/25 0:00:41 阅读更多 →

周新闻

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

直接铺开项目本身吧。这几个月我一直在折腾一件事:用Flutter给OpenHarmony做一款游戏集合类的App,说白了就是把若干小游戏塞进一个壳里,用统一入口分发。这个方向本身不算新鲜,真正让我花了不少心思的,是首页那堆游戏卡…

2026/9/24 14:34:13 阅读更多 →
Word表格编号全攻略:从列表编号到题注交叉引用

Word表格编号全攻略:从列表编号到题注交叉引用

写Word文档,最让人头疼的往往是那些“看起来不起眼”的小问题。比如表格编号这事:今天在表后面多加了两个空白行,明天给客户交稿前发现整个章节的编号全部错位,光是挨个改序号就能耗掉大半个下午。我前阵子帮人整理一份上百页的技…

2026/9/24 9:10:42 阅读更多 →
从第一个站到第二个站:独立开发者的静态网站选型与落地实践

从第一个站到第二个站:独立开发者的静态网站选型与落地实践

1. 项目概述1.1 核心需求解析做独立开发者这几年,说实话,第一个网站上线的那天晚上我兴奋得没睡着。但等它跑了半年,流量惨淡、功能臃肿、代码自己都懒得看第二遍之后,我才慢慢琢磨明白一个道理:第一个网站是练手&…

2026/9/24 14:33:56 阅读更多 →

月新闻

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能分类:[AI/大模型]细分主题:AI 增强型 CI/CD 流水线自动化与 GitOps 实践:Agent 工作流、工具调用与任务拆解:从原型到生产的验收清单很多团队在尝试用大…

2026/9/24 12:50:34 阅读更多 →
容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场分类:[工程技术]细分主题:Kubernetes 生产环境运维与排障实战:可复制的项目复盘模板与决策记录大部分团队的事故复盘报告,最后都变成了躺在 Confluence 或钉…

2026/9/24 14:33:48 阅读更多 →
容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步分类:[工程技术]细分主题:Docker 容器化技术与镜像安全管理:核心链路的逐步实现与关键代码取舍面对一个积累了五六年历史包袱的单体架构应用(包含 Web 接口、后台…

2026/9/24 12:49:17 阅读更多 →