![]() |
VOOZH | about |
dotnet add package Galosys.Foundation.Castle --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.Castle -Version 26.5.20.1
<PackageReference Include="Galosys.Foundation.Castle" Version="26.5.20.1" />
<PackageVersion Include="Galosys.Foundation.Castle" Version="26.5.20.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Castle" />Project file
paket add Galosys.Foundation.Castle --version 26.5.20.1
#r "nuget: Galosys.Foundation.Castle, 26.5.20.1"
#:package Galosys.Foundation.Castle@26.5.20.1
#addin nuget:?package=Galosys.Foundation.Castle&version=26.5.20.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Castle&version=26.5.20.1Install as a Cake Tool
成熟度: 🟢 稳定 — 生产可用,测试充分,活跃维护
基于 Castle.DynamicProxy 的 AOP 拦截模块,提供动态代理、特性驱动的拦截器,支持事务管理、重试策略、幂等性控制和异常日志记录。
[Transactional][Retryable](基于 Polly)[Idempotent][CatchLogging]dotnet add package Galosys.Foundation.Castle
// Program.cs - 方式一:使用 CastleCoreServiceProviderFactory
builder.Host.UseCastleCoreServiceProvider();
// Program.cs - 方式二:手动注册(需在所有服务注册后调用)
builder.Services.AddCastleInterceptors();
builder.Services.ConfigureCastleDynamicProxy();
public class OrderService
{
[Transactional]
public virtual async Task CreateOrderAsync(Order order)
{
// 方法执行在事务中
}
[Transactional(IsolationLevel = IsolationLevel.Serializable, Timeout = 30000)]
public virtual void ProcessPayment(Payment payment)
{
// 自定义隔离级别和超时时间
}
}
public class ExternalApiService
{
[Retryable(maxAttempts: 3)]
public virtual async Task<string> CallApiAsync()
{
// 失败时自动重试 3 次
}
[Retryable(maxAttempts: 5, MaxDelay = 10000, Multiplier = 2)]
public virtual async Task<Data> FetchDataAsync()
{
// 指数退避重试,最大延迟 10 秒
}
[Retryable(RetryFor = typeof(HttpRequestException))]
public virtual async Task<Response> ResilientCallAsync()
{
// 仅对特定异常类型重试
}
}
public class PaymentService
{
[Idempotent("payment:process")]
public virtual async Task<PaymentResult> ProcessPaymentAsync(PaymentRequest request)
{
// 相同 Key 的重复调用将返回缓存结果
}
}
public class BusinessService
{
[CatchLogging]
public virtual async Task ExecuteAsync()
{
// 执行耗时和异常信息将自动记录
}
}
// 方式一:继承 InterceptorAttribute
public class CustomInterceptorAttribute : InterceptorAttribute
{
protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
{
// 前置逻辑
await invocation.ProceedAsync();
// 后置逻辑
}
}
// 方式二:继承 InterceptorBase
public class CustomInterceptor : InterceptorBase
{
protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
{
await invocation.ProceedAsync();
}
}
// 使用
public class MyService
{
[CustomInterceptor]
public virtual void DoSomething() { }
}
| 类 | 说明 |
|---|---|
InterceptorAttribute |
拦截器特性基类,支持异步方法 |
InterceptorBase |
传统拦截器基类 |
TransactionalAttribute |
事务管理拦截器 |
RetryableAttribute |
重试策略拦截器(Polly) |
IdempotentAttribute |
幂等性控制拦截器 |
CatchLoggingAttribute |
异常日志记录拦截器 |
CastleCoreServiceCollectionExtensions |
DI 容器扩展方法 |
CastleCoreHostBuilderExtensions |
Host 构建器扩展方法 |
IAsyncInvocation |
异步调用上下文接口 |
ConfigureCastleDynamicProxy 必须在所有服务注册完成后调用virtual 方法或实现接口| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.20.1 | 98 | 5/20/2026 |
| 26.5.19.1 | 96 | 5/19/2026 |
| 26.5.18.1 | 95 | 5/18/2026 |
| 26.5.15.1 | 89 | 5/15/2026 |
| 26.5.12.3 | 92 | 5/12/2026 |
| 26.5.12.2 | 101 | 5/12/2026 |
| 26.4.27.1-rc1 | 99 | 4/26/2026 |
| 26.4.25.1-rc1 | 91 | 4/25/2026 |
| 26.4.22.2-rc7 | 102 | 4/22/2026 |
| 26.4.22.2-rc6 | 90 | 4/22/2026 |
| 26.4.22.2-rc4 | 91 | 4/22/2026 |
| 26.4.22.2-rc3 | 91 | 4/22/2026 |
| 26.4.19.1-rc1 | 94 | 4/19/2026 |
| 26.4.12.8-rc1 | 96 | 4/12/2026 |
| 26.4.12.7-rc1 | 94 | 4/12/2026 |
| 26.1.30.1-rc1 | 116 | 1/30/2026 |
| 26.1.29.1 | 119 | 1/29/2026 |
| 26.1.28.5 | 115 | 1/28/2026 |
| 26.1.28.4 | 114 | 1/28/2026 |
| 26.1.28.2 | 111 | 1/28/2026 |