Skip to content

powerumc/SimpleAop.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleAop

SimpleAop is library for your Aop or Dynamic Proxy programming. I converted it more simply from the old framework.

Here includes following libraries.

  • SimpleAop
    It needs Aop or Dynamic Proxy programming.

  • SimpleAop.Extensions.DependencyInjection
    Here includes IServiceCollection 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 need Interface declaring and Implementation class.

public interface IPrint
{
    void PrintMessage(string message);
}

public class Print : IPrint
{
    public void PrintMessage(string message)
    {
        Console.WriteLine(message);
    }
}

And to use it,

var type = DynamicProxyFactory.Create<IPrint, Print>();
var obj = (IPrint) Activator.CreateInstance(type);

obj.PrintMessage("Hello World");

The type generate random character from the Guid. It's just first SimpleAop version.

Aop Programming

Additionally, provider OnMethodBoundAspect attribute class. We just inherites it.

public class LoggingAspectAttribute : OnMethodBoundAspectAttribute
{
    public override void OnBefore(IAspectInvocation invocation)
    {
        Console.WriteLine($"--- Before: {invocation.Method}, {invocation.Object}, {string.Join(",", invocation.Parameters)} ---");
    }

    public override void OnAfter(IAspectInvocation invocation)
    {
        Console.WriteLine("--- After ---");
    }
}

And add logging attribute,

[LoggingAspect]
public class Print : IPrint
{
    public void PrintMessage(string message)
    {
        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

In Startup.cs file,

services.AddSingletonWithProxy<ITestService, TestService>();

I did make SimpleAop.Sample.AspNetCoreWeb project.

Let's run it, and watch 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy