RLei.Interceptor
1.0.0
dotnet add package RLei.Interceptor --version 1.0.0
NuGet\Install-Package RLei.Interceptor -Version 1.0.0
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="RLei.Interceptor" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RLei.Interceptor" Version="1.0.0" />
<PackageReference Include="RLei.Interceptor" />
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 RLei.Interceptor --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RLei.Interceptor, 1.0.0"
#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 RLei.Interceptor@1.0.0
#: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=RLei.Interceptor&version=1.0.0
#tool nuget:?package=RLei.Interceptor&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Interceptor
介绍
动态代理,用于实现AOP拦截,内部采用 DispatchProxy 实现
安装教程
NuGet:RLei.Interceptor
使用说明
- 声明接口,并提供实现类
internal interface ITestService
{
public int Add(int a, int b);
}
[Intercept(typeof(AOPTest))]//使用特性标注
internal class TestService : ITestService
{
public int Add(int a, int b)
{
Console.WriteLine($"正在执行--》Add({a},{b})");
// throw new Exception("方法执行--》测试异常");
return a + b;
}
}
- 提供AOP类,继承 IInterceptor 接口,并实现 Before 和 After 方法
internal class AOPTest : IInterceptor
{
public void BeforeAction(object?[]? args)
{
Console.WriteLine($"AOP方法执行之前,args:{args}");
// throw new Exception("异常测试(异常,但依然不能影响程序执行)");
}
public void AfterAction(object?[]? args, object result)
{
Console.WriteLine($"AOP方法执行之后,args:{args},result:{result}");
}
}
- 将相关类注入容器中,测试代理结果
//容器注册
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddTransient(typeof(AOPTest));
serviceCollection.AddTransient<ITestService, TestService>();
//构建容器
ServiceHelp.BuildServiceProvider(serviceCollection);
//用工厂获取代理实例
var s = ProxyFactory.Create<ITestService>();
var sum = s.Add(1, 2);
Console.WriteLine("执行完毕=====>" + sum);
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 was computed. 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.
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.1)
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.0 | 322 | 4/29/2023 |