CSharp: Builder Pattern using .net 10.0
项目结构:

/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : JewelryOrder.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Entities
{
public class JewelryOrder
{
public int OrderId { get; set; }
public string ProductName { get; set; } = string.Empty;
public DateTime CreateTime { get; set; } = DateTime.Now;
// 流程状态
public bool RawMaterialChecked { get; set; }
public bool DesignCompleted { get; set; }
public bool ProductionFinished { get; set; }
public bool QualityPassed { get; set; }
public bool Packaged { get; set; }
public bool Shipped { get; set; }
public bool FinanceSettled { get; set; }
// 系统状态
public string ProcessStatus { get; set; } = "Initialized";
public bool IsCompleted { get; set; }
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ProcessStep.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Enums
{
public enum ProcessStep
{
RawMaterialCheck,
Design,
Production,
QualityCheck,
Packaging,
Logistics,
Finance,
Marketing,
Business,
HrAdmin,
ItSupport
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IJewelryProcessBuilder.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Enums;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Builders
{
/// <summary>
/// 建造者接口
/// </summary>
public interface IJewelryProcessBuilder
{
IJewelryProcessBuilder CreateOrder(int orderId, string productName);
IJewelryProcessBuilder AddStep(ProcessStep step);
Task<JewelryOrder> BuildAsync(CancellationToken cancellationToken = default);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Common
{
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IThreadSafeLogger<out T>
{
void LogInformation(string message, params object[] args);
void LogError(Exception ex, string message, params object[] args);
void LogDebug(string message, params object[] args);
void LogWarning(string message, params object[] args);
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ServiceCollectionExtensions.cs
*/
using BuilderPattern.Core.Interfaces.Builders;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using BuilderPattern.Infrastructure.Logging;
using BuilderPattern.Schedulers;
using BuilderPattern.Schedulers.Abstractions;
using BuilderPattern.Services.Builders;
using BuilderPattern.Services.ProcessServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.File;
using System;
using System.IO;
namespace BuilderPattern.Infrastructure.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddJewelryBusinessSystem(this IServiceCollection services, LoggerOptions logOptions)
{
services.AddSingleton(logOptions);
string logRoot = Path.Combine(Directory.GetCurrentDirectory(), logOptions.LogRootDirectory);
Directory.CreateDirectory(logRoot);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: logOptions.OutputTemplate)
.WriteTo.File(
path: Path.Combine(logRoot, "info-.log"),
outputTemplate: logOptions.OutputTemplate,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: logOptions.RetainFileDays,
fileSizeLimitBytes: 1000000,
restrictedToMinimumLevel: LogEventLevel.Information,
rollOnFileSizeLimit: true)
.WriteTo.File(
path: Path.Combine(logRoot, "error-.log"),
outputTemplate: logOptions.OutputTemplate,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: logOptions.RetainFileDays,
fileSizeLimitBytes: 1000000,
restrictedToMinimumLevel: LogEventLevel.Error,
rollOnFileSizeLimit: true)
.CreateLogger();
services.AddLogging(builder =>
{
builder.ClearProviders();
builder.AddSerilog(dispose: true);
});
services.AddTransient(typeof(IThreadSafeLogger<>), typeof(ThreadSafeLogger<>));
// 业务服务注册
services.AddTransient<IRawMaterialService, RawMaterialService>();
services.AddTransient<IDesignService, DesignService>();
services.AddTransient<IProductionService, ProductionService>();
services.AddTransient<IQualityCheckService, QualityCheckService>();
services.AddTransient<IPackagingService, PackagingService>();
services.AddTransient<ILogisticsService, LogisticsService>();
services.AddTransient<IFinanceService, FinanceService>();
services.AddTransient<IMarketingService, MarketingService>();
services.AddTransient<IBusinessService, BusinessService>();
services.AddTransient<IHrAdminService, HrAdminService>();
services.AddTransient<IItService, ItService>();
services.AddTransient<IJewelryProcessBuilder, JewelryProcessBuilder>();
services.AddTransient<IProcessScheduler, JewelryProcessScheduler>();
return services;
}
}
}
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Infrastructure.Logging
{
public class FileLoggerConfiguration
{
public string RootDirectory { get; set; }
public string FileNamePattern { get; set; }
public string OutputTemplate { get; set; }
public bool Shared { get; set; }
public int RetainedFileCountLimit { get; set; }
public Func<string, LogLevel, bool>? Filter { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Infrastructure.Logging
{
public class LoggerOptions
{
/// <summary>日志根目录</summary>
public string LogRootDirectory { get; set; } = "Logs";
/// <summary>日志输出模板</summary>
public string OutputTemplate { get; set; } = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {CategoryName} | {Message:lj}{NewLine}{Exception}";
/// <summary>保留日志文件天数</summary>
public int RetainFileDays { get; set; } = 30;
/// <summary>多进程共享写入(高并发线程安全)</summary>
public bool SharedWrite { get; set; } = true;
}
}
using BuilderPattern.Core.Interfaces.Common;
using Microsoft.Extensions.Logging;
namespace BuilderPattern.Infrastructure.Logging
{
public class ThreadSafeLogger<T> : IThreadSafeLogger<T>
{
private readonly ILogger<T> _logger;
public ThreadSafeLogger(ILogger<T> logger)
{
_logger = logger;
}
public void LogInformation(string message, params object[] args)
{
_logger.LogInformation(message, args);
}
public void LogError(Exception ex, string message, params object[] args)
{
_logger.LogError(ex, message, args);
}
public void LogDebug(string message, params object[] args)
{
_logger.LogDebug(message, args);
}
public void LogWarning(string message, params object[] args)
{
_logger.LogWarning(message, args);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IProcessScheduler.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Schedulers.Abstractions
{
/// <summary>
/// 调度器接口
/// 调度层
/// </summary>
public interface IProcessScheduler
{
Task StartFullProcessAsync(CancellationToken cancellationToken = default);
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : JewelryProcessScheduler.cs
*/
using BuilderPattern.Core.Enums;
using BuilderPattern.Core.Interfaces.Builders;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Schedulers.Abstractions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Schedulers
{
/// <summary>
/// 调度器实现(统一入口、高并发、异步)
/// </summary>
/// <param name="logger"></param>
/// <param name="processBuilder"></param>
public class JewelryProcessScheduler(
ILogger<JewelryProcessScheduler> logger,
IJewelryProcessBuilder builder)
: IProcessScheduler
{
public async Task StartFullProcessAsync(CancellationToken cancellationToken = default)
{
logger.LogInformation("======================================================");
logger.LogInformation(" 珠宝企业全链路业务调度器启动 ");
logger.LogInformation("======================================================");
try
{
var order = await builder
.CreateOrder(3001, "18K金天然蓝宝石手镯")
.AddStep(ProcessStep.RawMaterialCheck)
.AddStep(ProcessStep.Design)
.AddStep(ProcessStep.Production)
.AddStep(ProcessStep.QualityCheck)
.AddStep(ProcessStep.Packaging)
.AddStep(ProcessStep.Logistics)
.AddStep(ProcessStep.Finance)
.AddStep(ProcessStep.Marketing)
.AddStep(ProcessStep.Business)
.AddStep(ProcessStep.HrAdmin)
.AddStep(ProcessStep.ItSupport)
.BuildAsync(cancellationToken);
logger.LogInformation("======================================================");
logger.LogInformation("调度完成 | 订单编号:{OrderId} | 流程状态:{Status} | 全部完成:{Complete}",
order.OrderId, order.ProcessStatus, order.IsCompleted);
logger.LogInformation("======================================================");
}
catch (Exception ex)
{
logger.LogError(ex, "珠宝全流程调度发生致命异常");
throw;
}
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : JewelryProcessBuilder.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Enums;
using BuilderPattern.Core.Interfaces.Builders;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using BuilderPattern.Services.ProcessServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.Builders
{
/// <summary>
/// 建造者实现(异步、线程安全、流程编排)
/// </summary>
/// <param name="logger"></param>
/// <param name="serviceProvider"></param>
public class JewelryProcessBuilder(
ILogger<JewelryProcessBuilder> logger,
IServiceProvider serviceProvider)
: IJewelryProcessBuilder
{
private readonly List<ProcessStep> _steps = new();
private JewelryOrder? _order;
public IJewelryProcessBuilder CreateOrder(int orderId, string productName)
{
_order = new JewelryOrder
{
OrderId = orderId,
ProductName = productName
};
logger.LogInformation("[建造者] 初始化订单:{OrderId} 产品:{ProductName}", orderId, productName);
return this;
}
public IJewelryProcessBuilder AddStep(ProcessStep step)
{
_steps.Add(step);
logger.LogDebug("[建造者] 追加流程步骤:{Step}", step);
return this;
}
public async Task<JewelryOrder> BuildAsync(CancellationToken cancellationToken = default)
{
if (_order is null)
throw new InvalidOperationException("请先调用 CreateOrder 初始化订单");
logger.LogInformation("[建造者] 订单{OrderId} 开始执行全流程,总步骤:{Count}", _order.OrderId, _steps.Count);
foreach (var step in _steps)
{
cancellationToken.ThrowIfCancellationRequested();
var service = ResolveStepService(step);
await service.ExecuteAsync(_order, cancellationToken);
}
_order.ProcessStatus = "AllStepsCompleted";
_order.IsCompleted = true;
logger.LogInformation("[建造者] 订单{OrderId} 全业务流程执行完毕", _order.OrderId);
return _order;
}
private IProcessService ResolveStepService(ProcessStep step)
{
return step switch
{
ProcessStep.RawMaterialCheck => serviceProvider.GetRequiredService<IRawMaterialService>(),
ProcessStep.Design => serviceProvider.GetRequiredService<IDesignService>(),
ProcessStep.Production => serviceProvider.GetRequiredService<IProductionService>(),
ProcessStep.QualityCheck => serviceProvider.GetRequiredService<IQualityCheckService>(),
ProcessStep.Packaging => serviceProvider.GetRequiredService<IPackagingService>(),
ProcessStep.Logistics => serviceProvider.GetRequiredService<ILogisticsService>(),
ProcessStep.Finance => serviceProvider.GetRequiredService<IFinanceService>(),
ProcessStep.Marketing => serviceProvider.GetRequiredService<IMarketingService>(),
ProcessStep.Business => serviceProvider.GetRequiredService<IBusinessService>(),
ProcessStep.HrAdmin => serviceProvider.GetRequiredService<IHrAdminService>(),
ProcessStep.ItSupport => serviceProvider.GetRequiredService<IItService>(),
_ => throw new NotSupportedException($"未实现流程步骤:{step}")
};
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IBusinessService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IBusinessService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IDesignService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IDesignService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IFinanceService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IFinanceService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IHrAdminService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IHrAdminService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IItService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IItService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ILogisticsService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface ILogisticsService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IMarketingService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IMarketingService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IPackagingService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IPackagingService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IProcessService.cs
*/
using BuilderPattern.Core.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IProcessService
{
Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default);
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IProductionService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IProductionService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IQualityCheckService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IQualityCheckService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : IRawMaterialService.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Core.Interfaces.Services
{
public interface IRawMaterialService : IProcessService;
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : BusinessService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class BusinessService(ILogger<BusinessService> logger) : IBusinessService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[业务对接] 订单{OrderId} 客户售后、订单归档", order.OrderId);
await Task.Delay(5, cancellationToken);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : DesignService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
public class DesignService(ILogger<DesignService> logger) : IDesignService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[设计制图] 订单{OrderId} 启动珠宝图纸绘制", order.OrderId);
order.DesignCompleted = true;
await Task.Delay(10, cancellationToken);
logger.LogInformation("[设计制图] 订单{OrderId} 设计图纸定稿完成");
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : FinanceService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class FinanceService(ILogger<FinanceService> logger) : IFinanceService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[财务结算] 订单{OrderId} 成本、回款台账登记", order.OrderId);
order.FinanceSettled = true;
await Task.Delay(10, cancellationToken);
logger.LogInformation("[财务结算] 订单{OrderId} 财务流程闭环");
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : HrAdminService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class HrAdminService(IThreadSafeLogger<HrAdminService> logger) : IHrAdminService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[人事行政] 订单{OrderId} 人力行政支持完成", order.OrderId);
await Task.Delay(5, cancellationToken);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ItService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class ItService(ILogger<ItService> logger) : IItService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[IT运维] 订单{OrderId} ERP、库存系统数据同步", order.OrderId);
await Task.Delay(5, cancellationToken);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ItService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class ItService(ILogger<ItService> logger) : IItService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[IT运维] 订单{OrderId} ERP、库存系统数据同步", order.OrderId);
await Task.Delay(5, cancellationToken);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : MarketingService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class MarketingService(ILogger<MarketingService> logger) : IMarketingService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[营销推广] 订单{OrderId} 新品上架、渠道投放", order.OrderId);
await Task.Delay(5, cancellationToken);
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : PackagingService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class PackagingService(ILogger<PackagingService> logger) : IPackagingService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[产品包装] 订单{OrderId} 礼盒、证书封装", order.OrderId);
order.Packaged = true;
await Task.Delay(8, cancellationToken);
logger.LogInformation("[产品包装] 订单{OrderId} 包装工序结束");
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : ProductionService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
public class ProductionService(ILogger<ProductionService> logger) : IProductionService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[加工生产] 订单{OrderId} 进入车间加工流程", order.OrderId);
order.ProductionFinished = true;
await Task.Delay(15, cancellationToken);
logger.LogInformation("[加工生产] 订单{OrderId} 毛坯加工全部完成");
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : QualityCheckService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
public class QualityCheckService(ILogger<QualityCheckService> logger) : IQualityCheckService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[质检检测] 订单{OrderId} 贵金属、钻石标准检测", order.OrderId);
order.QualityPassed = true;
await Task.Delay(10, cancellationToken);
logger.LogInformation("[质检检测] 订单{OrderId} 全部指标合格");
}
}
}
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : RawMaterialService.cs
*/
using BuilderPattern.Core.Entities;
using BuilderPattern.Core.Interfaces.Common;
using BuilderPattern.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace BuilderPattern.Services.ProcessServices
{
/// <summary>
/// 服务层
/// 业务服务实现
/// </summary>
/// <param name="logger"></param>
public class RawMaterialService(ILogger<RawMaterialService> logger) : IRawMaterialService
{
public async Task ExecuteAsync(JewelryOrder order, CancellationToken cancellationToken = default)
{
logger.LogInformation("[原料采购核验] 订单{OrderId} 开始原料核验:{ProductName}", order.OrderId, order.ProductName);
order.RawMaterialChecked = true;
await Task.Delay(10, cancellationToken);
logger.LogInformation("[原料采购核验] 订单{OrderId} 原料核验完成");
}
}
}
调用:
/*
# encoding: utf-8
# 版权所有 2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:建造者模式 Builder Patter 生成器模式
# 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 : BuilderBll.cs
*/
using BuilderPattern;
using BuilderPattern.Infrastructure.Logging;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using BuilderPattern.Infrastructure.DependencyInjection;
using BuilderPattern.Schedulers.Abstractions;
namespace BLL
{
public class BuilderBll
{
public void Demo()
{
var loggerOptions = new LoggerOptions
{
LogRootDirectory = "logs",
RetainFileDays = 30,
SharedWrite = true
};
var host = Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddJewelryBusinessSystem(loggerOptions);
})
.Build();
}
}
}
输出:
======================================================
2026-07-08 22:30:08.649 [INF] | 珠宝企业全链路业务调度器启动
2026-07-08 22:30:08.649 [INF] | ======================================================
2026-07-08 22:30:08.658 [INF] | [建造者] 初始化订单:3001 产品:18K金天然蓝宝石手镯
2026-07-08 22:30:08.663 [INF] | [建造者] 订单3001 开始执行全流程,总步骤:11
2026-07-08 22:30:08.664 [INF] | [原料采购核验] 订单3001 开始原料核验:18K金天然蓝宝石手镯
2026-07-08 22:30:08.691 [INF] | [原料采购核验] 订单{OrderId} 原料核验完成
2026-07-08 22:30:08.692 [INF] | [设计制图] 订单3001 启动珠宝图纸绘制
2026-07-08 22:30:08.708 [INF] | [设计制图] 订单{OrderId} 设计图纸定稿完成
2026-07-08 22:30:08.709 [INF] | [加工生产] 订单3001 进入车间加工流程
2026-07-08 22:30:08.738 [INF] | [加工生产] 订单{OrderId} 毛坯加工全部完成
2026-07-08 22:30:08.742 [INF] | [质检检测] 订单3001 贵金属、钻石标准检测
2026-07-08 22:30:08.754 [INF] | [质检检测] 订单{OrderId} 全部指标合格
2026-07-08 22:30:08.758 [INF] | [产品包装] 订单3001 礼盒、证书封装
2026-07-08 22:30:08.767 [INF] | [产品包装] 订单{OrderId} 包装工序结束
2026-07-08 22:30:08.768 [INF] | [物流配送] 订单3001 珠宝保价出库
2026-07-08 22:30:08.782 [INF] | [物流配送] 订单{OrderId} 已移交承运商
2026-07-08 22:30:08.785 [INF] | [财务结算] 订单3001 成本、回款台账登记
2026-07-08 22:30:08.797 [INF] | [财务结算] 订单{OrderId} 财务流程闭环
2026-07-08 22:30:08.799 [INF] | [营销推广] 订单3001 新品上架、渠道投放
2026-07-08 22:30:08.815 [INF] | [业务对接] 订单3001 客户售后、订单归档
2026-07-08 22:30:08.832 [INF] | [人事行政] 订单3001 人力行政支持完成
2026-07-08 22:30:08.848 [INF] | [IT运维] 订单3001 ERP、库存系统数据同步
2026-07-08 22:30:08.862 [INF] | [建造者] 订单3001 全业务流程执行完毕
2026-07-08 22:30:08.862 [INF] | ======================================================
2026-07-08 22:30:08.862 [INF] | 调度完成 | 订单编号:3001 | 流程状态:AllStepsCompleted | 全部完成:true
2026-07-08 22:30:08.862 [INF] | ======================================================
2026-07-08 22:30:53.106 [INF] | ======================================================
2026-07-08 22:30:53.140 [INF] | 珠宝企业全链路业务调度器启动
2026-07-08 22:30:53.140 [INF] | ======================================================
2026-07-08 22:30:53.148 [INF] | [建造者] 初始化订单:3001 产品:18K金天然蓝宝石手镯
2026-07-08 22:30:53.153 [INF] | [建造者] 订单3001 开始执行全流程,总步骤:11
2026-07-08 22:30:53.154 [INF] | [原料采购核验] 订单3001 开始原料核验:18K金天然蓝宝石手镯
2026-07-08 22:30:53.180 [INF] | [原料采购核验] 订单{OrderId} 原料核验完成
2026-07-08 22:30:53.181 [INF] | [设计制图] 订单3001 启动珠宝图纸绘制
2026-07-08 22:30:53.195 [INF] | [设计制图] 订单{OrderId} 设计图纸定稿完成
2026-07-08 22:30:53.196 [INF] | [加工生产] 订单3001 进入车间加工流程
2026-07-08 22:30:53.226 [INF] | [加工生产] 订单{OrderId} 毛坯加工全部完成
2026-07-08 22:30:53.227 [INF] | [质检检测] 订单3001 贵金属、钻石标准检测
2026-07-08 22:30:53.242 [INF] | [质检检测] 订单{OrderId} 全部指标合格
2026-07-08 22:30:53.243 [INF] | [产品包装] 订单3001 礼盒、证书封装
2026-07-08 22:30:53.257 [INF] | [产品包装] 订单{OrderId} 包装工序结束
2026-07-08 22:30:53.258 [INF] | [物流配送] 订单3001 珠宝保价出库
2026-07-08 22:30:53.272 [INF] | [物流配送] 订单{OrderId} 已移交承运商
2026-07-08 22:30:53.273 [INF] | [财务结算] 订单3001 成本、回款台账登记
2026-07-08 22:30:53.287 [INF] | [财务结算] 订单{OrderId} 财务流程闭环
2026-07-08 22:30:53.288 [INF] | [营销推广] 订单3001 新品上架、渠道投放
2026-07-08 22:30:53.304 [INF] | [业务对接] 订单3001 客户售后、订单归档
2026-07-08 22:30:53.319 [INF] | [人事行政] 订单3001 人力行政支持完成
2026-07-08 22:30:53.338 [INF] | [IT运维] 订单3001 ERP、库存系统数据同步
2026-07-08 22:30:53.349 [INF] | [建造者] 订单3001 全业务流程执行完毕
2026-07-08 22:30:53.349 [INF] | ======================================================
2026-07-08 22:30:53.349 [INF] | 调度完成 | 订单编号:3001 | 流程状态:AllStepsCompleted | 全部完成:true
2026-07-08 22:30:53.349 [INF] | ======================================================
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号