Sparkdo.Castle.Core 1.0.3

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Sparkdo.Castle.Core --version 1.0.3
                    
NuGet\Install-Package Sparkdo.Castle.Core -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sparkdo.Castle.Core" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.Castle.Core" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Sparkdo.Castle.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sparkdo.Castle.Core --version 1.0.3
                    
#r "nuget: Sparkdo.Castle.Core, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sparkdo.Castle.Core@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sparkdo.Castle.Core&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.Castle.Core&version=1.0.3
                    
Install as a Cake Tool

Sparkdo.Castle.Core

Sparkdo Castle.Core 库,提供基于 Castle DynamicProxy 的代理生成和拦截功能实现。

功能特性

  • 代理生成器:基于 Castle DynamicProxy 的代理生成器实现
  • 拦截适配器:将 Castle 拦截器适配到 Sparkdo 拦截器接口
  • 异步拦截支持:支持异步方法的拦截
  • 与 Sparkdo 框架无缝集成

安装

<PackageReference Include="Sparkdo.Castle.Core" Version="x.x.x" />

核心组件

模块

  • SparkdoCastleCoreModule: Castle.Core 模块,负责注册相关服务

代理生成器

  • CastleProxyGenerator: 基于 Castle DynamicProxy 的代理生成器实现

拦截器适配器

  • AsyncDeterminationInterceptor<TInterceptor>: 异步确定拦截器
  • CastleAsyncSparkdoInterceptorAdapter<TInterceptor>: Castle 异步拦截器适配器
  • CastleMethodInvocationAdapter: Castle 方法调用适配器
  • CastleMethodInvocationAdapterWithReturnValue<TResult>: 带返回值的 Castle 方法调用适配器
  • CastleMethodInvocationAdapterBase: Castle 方法调用适配器基类

使用示例

基本代理使用

public class MyService
{
    private readonly IProxyGenerator _proxyGenerator;
    
    public MyService(IProxyGenerator proxyGenerator)
    {
        _proxyGenerator = proxyGenerator;
    }
    
    public T CreateProxy<T>(T instance, params Type[] interceptorTypes) where T : class
    {
        return (T)_proxyGenerator.Create(typeof(T), instance, interceptorTypes);
    }
}

自定义拦截器

public class MyInterceptor : IInterceptor
{
    public async Task InterceptAsync(IMethodInvocation invocation)
    {
        // 在方法执行前的操作
        Console.WriteLine($"Before calling {invocation.Method.Name}");
        
        // 继续执行方法
        await invocation.ProceedAsync();
        
        // 在方法执行后的操作
        Console.WriteLine($"After calling {invocation.Method.Name}");
    }
}

模块配置

// 在模块配置中注册自定义拦截器
public override void Configure(IConfigureContext context)
{
    context.Services.AddTransient<MyInterceptor>();
}

扩展性

该库提供了完整的代理生成和拦截功能实现,可以通过以下方式扩展:

  1. 实现自定义的拦截器
  2. 实现自定义的代理生成器
  3. 通过继承和重写默认实现来定制代理功能

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sparkdo.Castle.Core:

Package Downloads
Sparkdo.Autofac

library for the Sparkdo framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4-preview.2 78 6/7/2026
1.0.4-preview.1 71 6/7/2026
1.0.3 152 6/6/2026
1.0.3-preview.1 76 5/17/2026
1.0.2 136 4/27/2026
1.0.2-preview.5 86 4/15/2026
1.0.2-preview.4 95 2/8/2026
1.0.2-preview.3 89 2/1/2026
1.0.2-preview.2 84 1/31/2026
1.0.2-preview.1 203 12/4/2025
1.0.1 222 11/27/2025
1.0.0 234 11/25/2025
1.0.0-preview.5 167 10/24/2025