AspNetCore.CoreExtension 1.0.1

dotnet add package AspNetCore.CoreExtension --version 1.0.1
NuGet\Install-Package AspNetCore.CoreExtension -Version 1.0.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="AspNetCore.CoreExtension" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.CoreExtension --version 1.0.1
#r "nuget: AspNetCore.CoreExtension, 1.0.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.
// Install AspNetCore.CoreExtension as a Cake Addin
#addin nuget:?package=AspNetCore.CoreExtension&version=1.0.1

// Install AspNetCore.CoreExtension as a Cake Tool
#tool nuget:?package=AspNetCore.CoreExtension&version=1.0.1

AspNetCore MVC or API应用中扩展使用Castle.Core IOC容器(支持伪属性注入)并增加AOP面向切面编程扩展

Startup.cs 中配置

public void ConfigureServices(IServiceCollection services)
        {       
                services.AddMvc()
                .AddControllersAsServices()//此服务必须添加
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
           //使用Castle.Core dll 重写IOC容器,支持PropertyInjection,
            services.AddCastleCoreService();
            //service打上AopAttribute的实现类标记
            services.AddTransient<ITestServiceA, TestServiceA>();
        }

业务Service

    public interface ITestServiceA
    {        
        [LogBefore]        
        [LogAfter]
        [Monitor]
        int Calculator(int a, int b);
    }
   public class TestServiceA : ITestServiceA
    {       
        public int Calculator(int p, int b)
        {
            return p + b;
        }
    }

添加自定义Aop业务

public class MonitorAttribute : AopAttribute
    {
        public override Action ExecutIntercepting(IInvocation invocation, Action action)
        {
            return () =>
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();            
               
                action.Invoke();//被标记执行的操作方法(必须调用此行操作,在该操作的前后可以定制自己的AOP业务逻辑,例如:痕迹处理,监控,日志...)

                stopwatch.Stop();
                Console.WriteLine($"=======耗时{stopwatch.ElapsedMilliseconds}ms=====");
            };
        }
    }

 public class LogBeforeAttribute : AopAttribute
    {
        public override Action ExecutIntercepting(IInvocation invocation, Action action)
        {
            return () =>
            {
                Console.WriteLine($"=====AOP  before This is {invocation.Method.Name}");
                foreach (var para in invocation.Arguments)
                {
                    Console.WriteLine($"para is {para}");
                }
                Console.WriteLine("====**************************************");
                action.Invoke();//被标记执行的操作方法(必须调用此行操作,在该操作的前后可以定制自己的AOP业务逻辑,例如:痕迹处理,监控,日志...)

            };
        }
    }

 public class LogAfterAttribute : AopAttribute
    {
        public override Action ExecutIntercepting(IInvocation invocation, Action action)
        {
            return () =>
            {
                action.Invoke();//被标记执行的操作方法(必须调用此行操作,在该操作的前后可以定制自己的AOP业务逻辑,例如:痕迹处理,监控,日志...)

                Console.WriteLine($"=====AOP   After This is {invocation.Method.Name}");
                foreach (var para in invocation.Arguments)
                {
                    Console.WriteLine($"para is {para}");
                }
                Console.WriteLine("====**************************************");
            };
        }
    }

controller下

    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        [PropertyInjection]//标记属性注入
        public ITestServiceA _testServiceA { get; set; }//注意:对象属性不能声明为空,且标记为public类型(例:public ITestServiceA _testServiceA=null) ,否则无法创建实例
        
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            ITestServiceA f = (ITestServiceA)this._testServiceA.AOP(typeof(ITestServiceA));          
            var re=f.Calculator(10,999);
            return new string[] { "value1", "this is test ioc " };
        }      
}
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. 
.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.1 505 7/2/2020
1.0.0 453 7/1/2020