项目结构/* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : IStaffFlyweight.cs */ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Core.Abstractions { /// summary /// 享元抽象接口珠宝行业岗位工作人员 /// 内部状态岗位名称、岗位职责、所属部门可共享常驻内存 /// 外部状态业务流水号、业务描述每次执行动态传入不存入享元对象 /// /summary public interface IStaffFlyweight { /// summary /// 执行岗位业务操作 /// /summary /// param namelogger日志实例/param /// param namebusinessNo业务流水号【外部状态】/param /// param namebusinessContext业务上下文描述【外部状态】/param void ExecuteWork(ILogger logger, string businessNo, string businessContext); /// summary /// 获取岗位名称内部共享状态 /// /summary string GetPositionName(); /// summary /// 获取岗位职责内部共享状态 /// /summary string GetDuty(); } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : IStaffFlyweightFactory.cs */ using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Core.Abstractions { /// summary /// 享元工厂接口负责创建、缓存岗位享元实例 /// 保证同一岗位全局只存在唯一实例实现对象复用降低GC压力 /// /summary public interface IStaffFlyweightFactory { /// summary /// 根据岗位名称获取享元对象 /// /summary /// param namepositionName岗位名称/param /// returns岗位享元实例/returns IStaffFlyweight GetStaffFlyweight(string positionName); /// summary /// 获取当前缓存享元数量 /// /summary int GetCacheCount(); /// summary /// 预加载珠宝全部业务岗位享元 /// /summary void PreloadAllJewelryPositions(); } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : PositionDutyModel.cs */ using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Core.Models { /// summary /// 岗位基础信息模型用于初始化享元内部状态 /// /summary public class PositionDutyModel { /// summary /// 岗位名称 /// /summary public string PositionName { get; set; } string.Empty; /// summary /// 所属部门 /// /summary public string Department { get; set; } string.Empty; /// summary /// 岗位职责描述 /// /summary public string Duty { get; set; } string.Empty; } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : JewelryStaffFlyweightFactory.cs */ using FlyweightPattern.Core.Abstractions; using FlyweightPattern.Core.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Infrastructure.Flyweight { /// summary /// 珠宝岗位享元工厂实现 /// ConcurrentDictionary 保证多线程并发安全缓存 /// /summary public class JewelryStaffFlyweightFactory : IStaffFlyweightFactory { private readonly ILoggerJewelryStaffFlyweightFactory _logger; /// summary /// 享元对象缓存池线程安全字典 /// Key岗位名称Value岗位享元实例 /// /summary private readonly ConcurrentDictionarystring, IStaffFlyweight _flyweightPool new(); public JewelryStaffFlyweightFactory(ILoggerJewelryStaffFlyweightFactory logger) { _logger logger; PreloadAllJewelryPositions(); } /// summary /// 获取岗位享元存在直接返回不存在抛出异常 /// /summary public IStaffFlyweight GetStaffFlyweight(string positionName) { if (string.IsNullOrWhiteSpace(positionName)) throw new ArgumentNullException(nameof(positionName)); if (_flyweightPool.TryGetValue(positionName, out var fly)) { _logger.LogDebug(命中享元缓存岗位{Position}, positionName); return fly; } throw new KeyNotFoundException($未预加载岗位【{positionName}】请检查岗位配置); } /// summary /// 获取缓存享元总数 /// /summary public int GetCacheCount() { return _flyweightPool.Count; } /// summary /// 预加载珠宝全业务岗位享元 /// /summary public void PreloadAllJewelryPositions() { _logger.LogInformation(开始预加载珠宝行业所有业务岗位享元对象); ListPositionDutyModel positionList new ListPositionDutyModel() { new PositionDutyModel{PositionName原料采购核验,Department供应链部,Duty贵金属/宝石原料采购、入库质检、原料成色核验、供应商对账}, new PositionDutyModel{PositionName设计制图,Department研发设计部,Duty首饰款式创意、CAD制图、3D建模、效果图输出、工艺图纸}, new PositionDutyModel{PositionName加工生产,Department生产车间,Duty失蜡铸造、执模、镶石、抛光、电镀、半成品加工}, new PositionDutyModel{PositionName质检,Department品控部,Duty成色检测、宝石分级、外观瑕疵检验、尺寸校验、合格判定}, new PositionDutyModel{PositionName包装,Department仓储部,Duty首饰清洁、礼盒封装、标签粘贴、产品入库分拣}, new PositionDutyModel{PositionName物流,Department仓储部,Duty订单打包、快递对接、物流跟踪、货品出入库管控}, new PositionDutyModel{PositionName财务,Department财务部,Duty成本核算、应收应付、开票、工资核算、资金管理}, new PositionDutyModel{PositionName营销推广,Department市场部,Duty线上线下推广、直播运营、活动策划、品牌宣传}, new PositionDutyModel{PositionName业务,Department销售部,Duty客户接待、订单洽谈、零售批发、售后沟通}, new PositionDutyModel{PositionName人事行政,Department行政人事部,Duty招聘、考勤、制度管理、后勤、办公物资管理}, new PositionDutyModel{PositionNameIT,Department信息部,Duty系统运维、服务器维护、软件故障处理、数据保障}, new PositionDutyModel{PositionName培训,Department培训部,Duty员工技能培训、销售话术培训、工艺知识教学} }; foreach (var item in positionList) { var flyweight new StaffFlyweight(item.PositionName, item.Department, item.Duty); _flyweightPool.TryAdd(item.PositionName, flyweight); _logger.LogDebug(岗位享元加载完成{Position}, item.PositionName); } _logger.LogInformation(岗位享元预加载完成缓存岗位总数{Count}, _flyweightPool.Count); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : StaffFlyweight.cs */ using FlyweightPattern.Core.Abstractions; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Infrastructure.Flyweight { /// summary /// 具体享元对象珠宝企业岗位人员 /// 内部状态不可变对象全局复用外部状态通过方法参数传入 /// /summary public class StaffFlyweight : IStaffFlyweight { /// summary /// 岗位名称 - 内部状态不可变 /// /summary private readonly string _positionName; /// summary /// 所属部门 - 内部状态不可变 /// /summary private readonly string _department; /// summary /// 岗位职责 - 内部状态不可变 /// /summary private readonly string _duty; /// summary /// 构造函数初始化固定内部状态 /// /summary /// param namepositionName岗位名称/param /// param namedepartment部门名称/param /// param nameduty岗位职责/param public StaffFlyweight(string positionName, string department, string duty) { _positionName positionName; _department department; _duty duty; } /// summary /// 执行岗位业务外部状态由调用方传入 /// /summary public void ExecuteWork(ILogger logger, string businessNo, string businessContext) { logger.LogInformation( [业务单号:{BusinessNo}]【{Department}-{Position}】开始处理业务{Context}岗位职责{Duty}, businessNo, _department, _positionName, businessContext, _duty); SimulateBusinessWork(logger, businessNo); } /// summary /// 模拟岗位业务执行逻辑 /// /summary private void SimulateBusinessWork(ILogger logger, string businessNo) { var random Random.Shared; int costMs random.Next(50, 200); Thread.Sleep(costMs); if (random.NextDouble() 0.08) { logger.LogWarning([业务单号:{BusinessNo}]【{Position}】业务存在轻微异常风险, businessNo, _positionName); } if (random.NextDouble() 0.03) { logger.LogError([业务单号:{BusinessNo}]【{Position}】业务处理出现临时故障, businessNo, _positionName); } logger.LogDebug([业务单号:{BusinessNo}]【{Position}】处理耗时{CostMs}ms, businessNo, _positionName, costMs); } /// summary /// /// /summary /// returns/returns public string GetPositionName() { return _positionName; } public string GetDuty() { return _duty; } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : LoggingConfiguration.cs */ using Karambolo.Extensions.Logging.File; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace FlyweightPattern.Infrastructure.Logging { public static class LoggingConfiguration { public static void ConfigureLogger(ILoggingBuilder loggingBuilder) { loggingBuilder.ClearProviders(); loggingBuilder.AddConsole(options { options.FormatterName Simple; }); loggingBuilder.AddFile(fileBuilder { fileBuilder.RootPath Directory.GetCurrentDirectory(); string todayDate DateTime.Now.ToString(yyyy-MM-dd); string logDir Path.Combine(fileBuilder.RootPath, Logs, todayDate); Directory.CreateDirectory(logDir); fileBuilder.Files new[] { new LogFileOptions { Path $Logs/{todayDate}/app-debug.log, MaxFileSize 50 * 1024 * 1024, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Debug }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-info.log, MaxFileSize 50 * 1024 * 1024, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Information }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-warn.log, MaxFileSize 50 * 1024 * 1024, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Warning }, IncludeScopes true }, new LogFileOptions { Path $Logs/{todayDate}/app-error.log, MaxFileSize 50 * 1024 * 1024, MinLevel new Dictionarystring, LogLevel { [] LogLevel.Error }, IncludeScopes true } }; }); loggingBuilder.SetMinimumLevel(LogLevel.Debug); } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : ScheduleStartupService.cs */ using FlyweightPattern.Scheduler.Jobs; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Quartz; using Quartz.Core; using Quartz.Impl; using Quartz.Util; using Quartz.Job; using Quartz.Impl.Calendar; using Quartz.Impl.Matchers; using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Scheduler.HostedServices { /// summary /// 调度初始化托管服务 /// 程序启动注册触发器程序关闭优雅停止调度器 /// /summary public class ScheduleStartupService : IHostedService { private readonly ILoggerScheduleStartupService _logger; private readonly ISchedulerFactory _schedulerFactory; private IScheduler? _scheduler; /// summary /// /// /summary /// param namelogger/param /// param nameschedulerFactory/param public ScheduleStartupService(ILoggerScheduleStartupService logger, ISchedulerFactory schedulerFactory) { _logger logger; _schedulerFactory schedulerFactory; } /// summary /// Host启动时执行 /// /summary /// param namecancellationToken/param /// returns/returns public async Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation(开始初始化Quartz定时调度器); _scheduler await _schedulerFactory.GetScheduler(cancellationToken); // 任务1间隔30秒循环执行 var normalJobKey new JobKey(JewelryNormalFlowJob, JewelryGroup); IJobDetail normalJob JobBuilder.CreateJewelryScheduleJob() .WithIdentity(normalJobKey) .StoreDurably() .Build(); normalJob.JobDataMap.Put(BusinessNo, JH-SCHED-001); normalJob.JobDataMap.Put(OrderTitle, 定时自动-日常首饰生产订单); ITrigger normalTrigger TriggerBuilder.Create() .WithIdentity(NormalFlowTrigger, JewelryGroup) .ForJob(normalJobKey) .StartNow() .WithSimpleSchedule(x x.WithIntervalInSeconds(30).RepeatForever()) .Build(); // 任务2Cron每日凌晨2点批量执行10单并发 var batchJobKey new JobKey(JewelryBatchJob, JewelryGroup); IJobDetail batchJob JobBuilder.CreateJewelryScheduleJob() .WithIdentity(batchJobKey) .StoreDurably() .Build(); batchJob.JobDataMap.Put(ConcurrentOrderCount, 10); ITrigger batchTrigger TriggerBuilder.Create() .WithIdentity(BatchFlowTrigger, JewelryGroup) .ForJob(batchJobKey) .StartNow() .WithCronSchedule(0 0 2 * * ?) .Build(); await _scheduler.AddJob(normalJob, false, cancellationToken); await _scheduler.ScheduleJob(normalTrigger, cancellationToken); await _scheduler.AddJob(batchJob, false, cancellationToken); await _scheduler.ScheduleJob(batchTrigger, cancellationToken); await _scheduler.Start(cancellationToken); _logger.LogInformation(Quartz调度器启动成功定时任务已加载); } /// summary /// Host停止优雅关闭调度器 /// /summary /// param namecancellationToken/param /// returns/returns public async Task StopAsync(CancellationToken cancellationToken) { if (_scheduler ! null !_scheduler.IsShutdown) { _logger.LogInformation(准备停止Quartz调度器等待运行中任务完成...); await _scheduler.Shutdown(waitForJobsToComplete: true, cancellationToken); _logger.LogInformation(Quartz调度器已正常关闭); } } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : JewelryScheduleJob.cs */ using FlyweightPattern.Business.Abstractions; using Microsoft.Extensions.Logging; using Quartz; using Quartz.Core; using Quartz.Impl; using Quartz.Util; using Quartz.Job; using Quartz.Impl.Calendar; using Quartz.Impl.Matchers; using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Scheduler.Jobs { /// summary /// 珠宝业务定时任务Job /// Quartz托管任务支持DI注入依赖 /// /summary public class JewelryScheduleJob : IJob { private readonly ILoggerJewelryScheduleJob _logger; private readonly IJewelryBusinessScheduler _businessScheduler; public JewelryScheduleJob(ILoggerJewelryScheduleJob logger, IJewelryBusinessScheduler businessScheduler) { _logger logger; _businessScheduler businessScheduler; } /// summary /// Quartz任务执行入口 /// /summary /// param namecontext/param /// returns/returns public async Task Execute(IJobExecutionContext context) { try { JobKey jobKey context.JobDetail.Key; _logger.LogInformation(【定时任务触发】任务Key:{JobKey}, context.JobDetail.Key); var businessNo context.JobDetail.JobDataMap.GetString(BusinessNo); var orderTitle context.JobDetail.JobDataMap.GetString(OrderTitle); int concurrentCount; context.JobDetail.JobDataMap.TryGetInt(ConcurrentOrderCount, out concurrentCount); if (!string.IsNullOrEmpty(businessNo) !string.IsNullOrEmpty(orderTitle)) { await _businessScheduler.RunFullJewelryBusinessFlowAsync(businessNo, orderTitle); } else if (concurrentCount 0) { await _businessScheduler.RunMultiOrderConcurrentAsync(concurrentCount); } else { _logger.LogWarning(定时任务未传入有效业务参数跳过业务执行); } _logger.LogInformation(【定时任务执行完成】任务Key:{JobKey}, context.JobDetail.Key); } catch (Exception ex) { _logger.LogError(ex, 【定时任务执行异常】任务Key:{JobKey}, context.JobDetail.Key); throw; } } } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : IJewelryBusinessScheduler.cs */ using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Business.Abstractions { /// summary /// 珠宝业务调度器抽象 /// 负责驱动整条珠宝业务流水线执行 /// /summary public interface IJewelryBusinessScheduler { /// summary /// 执行单条订单完整业务流程 /// /summary /// param namebusinessNo业务流水号/param /// param nameorderTitle订单名称/param Task RunFullJewelryBusinessFlowAsync(string businessNo, string orderTitle); /// summary /// 并发批量执行多条订单 /// /summary /// param nameorderCount模拟订单数量/param Task RunMultiOrderConcurrentAsync(int orderCount); } } /* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述结构型模式 Structural Patterns 享元模式Flyweight 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 : JewelryBusinessScheduler.cs */ using FlyweightPattern.Business.Abstractions; using FlyweightPattern.Core.Abstractions; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text; namespace FlyweightPattern.Business.Implementations { /// summary /// 珠宝业务流水线调度实现 /// 串联全流程岗位通过享元工厂复用岗位实例 /// /summary public class JewelryBusinessScheduler : IJewelryBusinessScheduler { private readonly ILoggerJewelryBusinessScheduler _logger; private readonly IStaffFlyweightFactory _flyweightFactory; public JewelryBusinessScheduler(ILoggerJewelryBusinessScheduler logger, IStaffFlyweightFactory flyweightFactory) { _logger logger; _flyweightFactory flyweightFactory; } /// summary /// 单订单完整业务流水线 /// /summary public async Task RunFullJewelryBusinessFlowAsync(string businessNo, string orderTitle) { _logger.LogInformation(启动珠宝完整业务流程单号:{BusinessNo},订单:{OrderTitle}, businessNo, orderTitle); Liststring positionSequence new Liststring() { 原料采购核验, 设计制图, 加工生产, 质检, 包装, 物流, 财务, 营销推广, 业务, 人事行政, IT, 培训 }; foreach (var position in positionSequence) { var staff _flyweightFactory.GetStaffFlyweight(position); staff.ExecuteWork(_logger, businessNo, $订单[{orderTitle}]流程处理); await Task.Delay(30); } _logger.LogInformation(珠宝业务流程全部执行完成单号:{BusinessNo}, businessNo); } /// summary /// 多订单并发执行测试高并发场景 /// /summary public async Task RunMultiOrderConcurrentAsync(int orderCount) { _logger.LogInformation(开始并发模拟{OrderCount}条珠宝订单业务流程, orderCount); ListTask taskList new ListTask(); for (int i 1; i orderCount; i) { string orderNo $JH{DateTime.Now:yyyyMMdd}{i:D06}; string orderName $定制首饰订单-{i}号; taskList.Add(RunFullJewelryBusinessFlowAsync(orderNo, orderName)); } await Task.WhenAll(taskList); _logger.LogInformation(全部并发订单处理完毕); } } }调用/* # encoding: utf-8 # 版权所有 2026 ©涂聚文有限公司™ ® # 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 # 描述享元模式 Flyweight 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 : FlyweightBll.cs */ using FlyweightPattern.Business.Abstractions; using FlyweightPattern.Business.Implementations; using FlyweightPattern.Core.Abstractions; using FlyweightPattern.Infrastructure.Flyweight; using FlyweightPattern.Infrastructure.Logging; using FlyweightPattern.Scheduler.HostedServices; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Quartz; using Quartz.Core; using Quartz.Impl; using Quartz.Util; using Quartz.Job; using Quartz.Impl.Calendar; using Quartz.Impl.Matchers; using System; using System.Collections.Generic; using System.Text; namespace BLL { public class FlyweightBll { //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); public async void Demo() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var host Host.CreateDefaultBuilder() .ConfigureLogging((context, loggingBuilder) { LoggingConfiguration.ConfigureLogger(loggingBuilder); }) .ConfigureServices((context, services) { // Core Infrastructure services.AddSingletonIStaffFlyweightFactory, JewelryStaffFlyweightFactory(); // Business Layer services.AddTransientIJewelryBusinessScheduler, JewelryBusinessScheduler(); // Quartz 定时调度 services.AddQuartz(q { q.UseMicrosoftDependencyInjectionJobFactory(); q.UseInMemoryStore(); }); services.AddQuartzHostedService(opt //AddQuartzHostedService { opt.WaitForJobsToComplete true; //WaitForJobsToComplete }); services.AddHostedServiceScheduleStartupService(); }) .Build(); // 可选手动测试执行 //var businessScheduler host.Services.GetRequiredServiceIJewelryBusinessScheduler(); //await businessScheduler.RunFullJewelryBusinessFlowAsync(JH20260721001, 18K金钻石戒指订单); //await businessScheduler.RunMultiOrderConcurrentAsync(5); await host.RunAsync(); } } }输出