SimpleAop is library for your Aop or Dynamic Proxy programming.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
samples
src
tests/SimpleAopTests
.gitignore
LICENSE
README.md
SimpleAop.sln

README.md

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