Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

SimpleAop is library for your AOP or dynamic proxy programming.

License

NotificationsYou must be signed in to change notification settings

powerumc/SimpleAop.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Dynamic Proxy Programming

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.

Aop Programming

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 ---

ASP.NET Core or .NET Core

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.

Have a issue?

https://github.com/powerumc/SimpleAop/issues

About

SimpleAop is library for your AOP or dynamic proxy programming.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp