A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pamidur/aspect-injector below:

pamidur/aspect-injector: AOP framework for .NET (c#, vb, etc)

I have never asked for any donations, but today, I ask you, please, consider donating Ukrainian Army.
You can find official ways to do it here or you can donate to the biggest charity organization here People need to be alive to create open source projects! Aspect Injector

Aspect Injector is an attribute-based framework for creating and injecting aspects into your .net assemblies.

> dotnet add package AspectInjector

Check out samples and docs

Known Issues / Limitations Create an aspect with simple advice:
[Aspect(Scope.Global)]
[Injection(typeof(LogCall))]
public class LogCall : Attribute
{
    [Advice(Kind.Before)] // you can have also After (async-aware), and Around(Wrap/Instead) kinds
    public void LogEnter([Argument(Source.Name)] string name)
    {
        Console.WriteLine($"Calling '{name}' method...");   //you can debug it	
    }
}
[LogCall]
public void Calculate() 
{ 
    Console.WriteLine("Calculated");
}

Calculate();
$ dotnet run
Calling 'Calculate' method...
Calculated
Create an aspect with mixin:
public interface IInitializable
{
    void Init();
}

[Aspect(Scope.PerInstance)]
[Injection(typeof(Initializable))]
[Mixin(typeof(IInitializable))]
public class Initializable : IInitializable, Attribute
{
    public void Init()
    {
        Console.WriteLine("Initialized!");
    }
}
[Initializable]
public class Target
{ 
}

var target = new Target() as IInitializable;
target.Init();
$ dotnet run
Initialized!

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4