Sparkdo.Castle.Core 1.0.2-preview.1

This is a prerelease version of Sparkdo.Castle.Core.
dotnet add package Sparkdo.Castle.Core --version 1.0.2-preview.1
                    
NuGet\Install-Package Sparkdo.Castle.Core -Version 1.0.2-preview.1
                    
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.2-preview.1" />
                    
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.2-preview.1" />
                    
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.2-preview.1
                    
#r "nuget: Sparkdo.Castle.Core, 1.0.2-preview.1"
                    
#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.2-preview.1
                    
#: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.2-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.Castle.Core&version=1.0.2-preview.1&prerelease
                    
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 net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2-preview.1 154 12/4/2025
1.0.1 181 11/27/2025
1.0.0 186 11/25/2025
1.0.0-preview.5 115 10/24/2025