Skip to content

🧩 A simple auto loader that scans for service classes and configure in the dependency injection provider.

License

Notifications You must be signed in to change notification settings

dgenezini/DIContextAutoLoader

Repository files navigation

DIContextAutoLoader

NuGet version (DIContextAutoLoader)

A simple auto loader that scans for service classes and configure in the dependency injection provider.

Core Package

    Install-Package DIContextAutoLoader

Usage

Annotate your services with the ConfigureInjection attribute:

[ConfigureInjection]
public class ServiceOne
{
    ...
}

Optionally you can specify the lifetime. (Default is Scoped.)

[ConfigureInjection(Lifetime = InjectionLifetime.Singleton)]
public class ServiceOne
{
    ...
}

You can also specify the InjectionType. (Default is Auto.)

  • Auto = If the class implement interfaces, DI configuration will be done by them. If not, it will be done by the implementation type;
  • ByImplementationType = DI configuration will be done by implementation type;
  • ByServiceType = DI configuration will be done by service/interface types;
  • ByBoth = DI configuration will be done by service/interface types and by implementation type.
[ConfigureInjection(Lifetime = InjectionLifetime.Transient, InjectionType = InjectionType.ByServiceType)]
public class ServiceTwo: ISomeService
{
    ...
}

DI Extensions

Usage

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AutoLoadServices(typeof(SomeTypeInAssembly).Assembly);
 
        ...
    }
}

About

🧩 A simple auto loader that scans for service classes and configure in the dependency injection provider.

Resources

License

Stars

Watchers

Forks

Languages