Aiursoft Scanner

An Automatic dependencies management system for ASP.NET Core and powers Aiursoft.

Document

Aiursoft Scanner.Abstract

NuGet version (Aiursoft.Scanner.Abstract) Build status

The abstract layer for Aiursoft.Scanner

When should I use this

If you are trying to develope a service which supports Aiursoft.Scanner to be scanned, but do NOT reference a dependency injection framework, this one is just for you.

View it on github
Document

Aiursoft Scanner

NuGet version (Aiursoft.Scanner) Build status

An Automatic dependencies management system for ASP.NET Core and powers Aiursoft.

Why this project

The traditional way to add dependencies is:

service.AddScoped<MyScopedDependency>();

Which means that you have to manually inject all dependencies. When you have too much of them, it is possible to make a mistake.

How to use Aiursoft.Scanner

First, install Aiursoft.Scanner to your ASP.NET Core project from nuget.org:

dotnet add package Aiursoft.Scanner

Add the interface to your class like this:

using Aiursoft.Scanner.Interfaces;

public class MySingletonService : ISingletonDependency
{

}

public class MyScopedService : IScopedDepdency
{

}

public class MyTransientService : ITransientDepdency
{

}

And just call this in your StartUp.cs:

using Aiursoft.Scanner;

services.AddScannedDependencies();

That's all! All your dependencies are registered. Just use it like previous before:

public class MyController : Controller
{
    private readonly MyScopedService _service;
    public MyController(MyScopedService service)
    {
        _service = service;
    }
}

Advanced usage

When you want to register a dependency which implements an abstract, your privouse way is like:

public class MyClass : IAbstract
{

}
service.AddScoped<IAbstract, MyClass>();

That's fine. But now we want to register this automatically.

Add the dependency interface to your service like this:

public class MyClass : IAbstract, IScopedDependency
{

}

When you are registering all dependencies in your StartUp.cs, tell us that your project supports your abstract.

services.AddScannedDependencies(typeof(IAbstract));

And you can call it with multiple abstracts:

services.AddScannedDependencies(typeof(IAbstract1), typeof(IAbstract2), typeof(IAbstract3));

That's all! Enjoy!

View it on github