- Notifications
You must be signed in to change notification settings - Fork5
SimpleAop is library for your AOP or dynamic proxy programming.
License
powerumc/SimpleAop.Net
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
SimpleAop is library for your Aop or Dynamic Proxy programming. I converted it more simply from theold framework.
Here includes following libraries.
SimpleAop
It needs Aop or Dynamic Proxy programming.SimpleAop.Extensions.DependencyInjection
Here includesIServiceCollection
extension class for .NET Core or ASP.NET Core.
To install, run following command or Nuget browser of visual studio.
Functionally list.
- Dynamic Proxy
- Aop of methods and classes.
- General methods.
- yield return
- async/await
- Generate constructors.
dotnet add package SimpleAop
dotnet add package SimpleAop.Extensions.DependencyInjection
It's simple. We just needInterface declaring andImplementation class.
publicinterfaceIPrint{voidPrintMessage(stringmessage);}publicclassPrint:IPrint{publicvoidPrintMessage(stringmessage){Console.WriteLine(message);}}
And to use it,
vartype=DynamicProxyFactory.Create<IPrint,Print>();varobj=(IPrint)Activator.CreateInstance(type);obj.PrintMessage("Hello World");
Thetype
generate random character from theGuid
. It's just first SimpleAop version.
Additionally, providerOnMethodBoundAspect
attribute class. We just inherites it.
publicclassLoggingAspectAttribute:OnMethodBoundAspectAttribute{publicoverridevoidOnBefore(IAspectInvocationinvocation){Console.WriteLine($"--- Before:{invocation.Method},{invocation.Object},{string.Join(",",invocation.Parameters)} ---");}publicoverridevoidOnAfter(IAspectInvocationinvocation){Console.WriteLine("--- After ---");}}
And add logging attribute,
[LoggingAspect]publicclassPrint:IPrint{publicvoidPrintMessage(stringmessage){Console.WriteLine(message);}}
So result is,
--- Before: Void PrintMessage(System.String), 9a19fdd7e64943c9b22ae2c79a886b50, Hello World ---Hello World--- After ---
Provide some methods is,
- AddWithProxy
- AddTransientWithProxy
- AddScopedWithProxy
- AddSingletonWithProxy
InStartup.cs
file,
services.AddSingletonWithProxy<ITestService,TestService>();
I did makeSimpleAop.Sample.AspNetCoreWeb
project.
Let's run it, andwatch the console log.
About
SimpleAop is library for your AOP or dynamic proxy programming.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.