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

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

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

2026/7/19 1:31:20 阅读更多 →
助睿浏览器市场与用户画像分析-数据分析

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

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

2026/7/19 1:31:20 阅读更多 →

最新新闻

让 AI 真正动手:Swees — 手机上的 AI Agent 架构全解析

让 AI 真正动手:Swees — 手机上的 AI Agent 架构全解析

本文深入剖析开源项目 Swees 的技术架构,探讨如何在无 root 的 Android 手机上构建一个真正能「动手」的 AI Agent。 一、引言:AI 只能说,不能做? 你大概有过这样的体验:在手机上问 AI「帮我写个 Python 脚本处理 CS…

2026/7/19 3:16:01 阅读更多 →
Android构建变体(Build Variants)配置与实战指南

Android构建变体(Build Variants)配置与实战指南

1. 理解构建变体的核心概念在Android开发中,构建变体(Build Variants)是Gradle和Android Gradle插件提供的一个强大功能,它允许开发者基于同一套代码库构建出不同版本的应用。每个构建变体都是构建类型(Build Type)和产品风味(Product Flavor)的组合产物…

2026/7/19 3:16:01 阅读更多 →
嵌入式C语言

嵌入式C语言

C语言数据类型在STM32中数据类型的关键字名字被换为:stdint关键字里对应的名称。使用新名称需要包含stdint.h头文件。C语言宏定义关键字:#define用途:用一个字符串代替一个数字,便于理解,防止出错;提取程序…

2026/7/19 3:16:01 阅读更多 →
AI Agent零代码数据分析:智析Agent让Excel分析像聊天一样简单

AI Agent零代码数据分析:智析Agent让Excel分析像聊天一样简单

很多业务人员都遇到过这样的困境:手头有大量Excel数据需要分析,但不会写Python代码,复杂的SQL查询更是让人头疼。传统的Excel函数和透视表虽然强大,但学习成本高,处理复杂分析时效率低下。现在,借助AI Agen…

2026/7/19 3:16:01 阅读更多 →
C#实现中值滤波去除椒盐噪声的原理与优化

C#实现中值滤波去除椒盐噪声的原理与优化

1. 中值滤波与椒盐噪声的对抗原理椒盐噪声是数字图像处理中最常见的噪声类型之一,表现为图像中随机出现的黑白像素点(就像撒了椒盐一样)。这种噪声通常由传感器故障、传输错误或存储介质问题引起。在8位灰度图像中,椒盐噪声表现为…

2026/7/19 3:16:01 阅读更多 →
Python模拟登录实战:从基础到高级技巧

Python模拟登录实战:从基础到高级技巧

1. 项目概述:Python模拟登录的核心价值第一次接触Python模拟登录时,我被这个看似简单却蕴含多种技术可能性的项目深深吸引。模拟登录本质上是通过代码自动完成网站的身份验证流程,这不仅是爬虫开发的必备技能,更是理解Web交互原理…

2026/7/19 3:15:01 阅读更多 →

日新闻

Go语言静态资源打包方案对比与实践指南

Go语言静态资源打包方案对比与实践指南

1. 项目背景与核心需求在Go语言开发中,我们经常需要处理静态资源文件的打包问题。无论是Web应用的模板文件、前端资源,还是配置文件、证书等,都需要随程序一起分发。传统做法是将这些文件与编译后的二进制文件放在同一目录下,但这…

2026/7/19 0:00:40 阅读更多 →
Go语言实现高性能LDAP认证服务的架构与实践

Go语言实现高性能LDAP认证服务的架构与实践

1. 项目背景与核心价值LDAP(轻量级目录访问协议)作为企业级身份认证的黄金标准,已经服务了超过80%的财富500强公司。我在金融科技领域实施统一认证体系时,发现传统Java方案存在启动慢、内存占用高等痛点。而Go语言凭借其协程并发模…

2026/7/19 0:00:40 阅读更多 →
【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

更多请点击: https://intelliparadigm.com 第一章:AI面试官实战指南的核心价值与适用场景 AI面试官并非替代人类HR的“黑箱工具”,而是以可解释、可审计、可迭代的方式,赋能招聘全链路的关键基础设施。其核心价值在于将主观经验沉…

2026/7/19 0:00:40 阅读更多 →

周新闻

Go语言静态资源打包方案对比与实践指南

Go语言静态资源打包方案对比与实践指南

1. 项目背景与核心需求在Go语言开发中,我们经常需要处理静态资源文件的打包问题。无论是Web应用的模板文件、前端资源,还是配置文件、证书等,都需要随程序一起分发。传统做法是将这些文件与编译后的二进制文件放在同一目录下,但这…

2026/7/19 0:00:40 阅读更多 →
Go语言实现高性能LDAP认证服务的架构与实践

Go语言实现高性能LDAP认证服务的架构与实践

1. 项目背景与核心价值LDAP(轻量级目录访问协议)作为企业级身份认证的黄金标准,已经服务了超过80%的财富500强公司。我在金融科技领域实施统一认证体系时,发现传统Java方案存在启动慢、内存占用高等痛点。而Go语言凭借其协程并发模…

2026/7/19 0:00:40 阅读更多 →
【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

更多请点击: https://intelliparadigm.com 第一章:AI面试官实战指南的核心价值与适用场景 AI面试官并非替代人类HR的“黑箱工具”,而是以可解释、可审计、可迭代的方式,赋能招聘全链路的关键基础设施。其核心价值在于将主观经验沉…

2026/7/19 0:00:40 阅读更多 →

月新闻