Yozian.DependencyInjectionPlus 1.0.5

Easy for DI register, auto register services, decorate service with attribute

Install-Package Yozian.DependencyInjectionPlus -Version 1.0.5
dotnet add package Yozian.DependencyInjectionPlus --version 1.0.5
<PackageReference Include="Yozian.DependencyInjectionPlus" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Yozian.DependencyInjectionPlus --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Make Dependency Injection Easily

Features

  • Write Once, Register all.
  • Register services globally which decorated by attributes(TransientService, ScopedService, SingletonService)
  • Auto register service with implement Type also with provided interfaces.
  • Register services for specify assembly.
  • Service's type filter while regstering.
  • Register method is an extension method on IServiceColletion

Example

Register for once

    
    // sample for .net core 
     public void ConfigureServices(IServiceCollection services)
     {
        // just choose one of them to fit your scenario


        // 1. register services
        services.RegisterServices();

        // 2. register services only in those assmbly name start with "DependencyInjectionSample"
        services.RegisterServices("DependencyInjectionSample");


        // 3. register services and has some condition
        services.RegisterServices("", type =>
        {
            return type.Name.Contains("Service");
        });


        // 4. regiter services for specify assembly
        services.RegisterServicesOfAssembly(new { }.GetType().Assembly);
    }

Decorated Service


    [TransientService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }

    [ScopedService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }


    [SingletonService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }


Decoreated service with interfaces

Provide one or more interface types


    [ScopedService(typeof(IWorker), typeof(IDriver))]
    public class WorkService : IWorker, IDriver
    {
        public void DoWork()
        {
            Console.WriteLine(nameof(this.DoWork));
        }

        public void Drive() => throw new NotImplementedException();
    }

Output registered types in STD out

DependencyInjectionSample project shows

Register Transient Services , Total: 1
     [ConcretType : SerivceTypes]
     (1) DemoService: DemoService
Register Scoped Services , Total: 1
     [ConcretType : SerivceTypes]
     (1) WorkService: WorkService, IWorker

Make Dependency Injection Easily

Features

  • Write Once, Register all.
  • Register services globally which decorated by attributes(TransientService, ScopedService, SingletonService)
  • Auto register service with implement Type also with provided interfaces.
  • Register services for specify assembly.
  • Service's type filter while regstering.
  • Register method is an extension method on IServiceColletion

Example

Register for once

    
    // sample for .net core 
     public void ConfigureServices(IServiceCollection services)
     {
        // just choose one of them to fit your scenario


        // 1. register services
        services.RegisterServices();

        // 2. register services only in those assmbly name start with "DependencyInjectionSample"
        services.RegisterServices("DependencyInjectionSample");


        // 3. register services and has some condition
        services.RegisterServices("", type =>
        {
            return type.Name.Contains("Service");
        });


        // 4. regiter services for specify assembly
        services.RegisterServicesOfAssembly(new { }.GetType().Assembly);
    }

Decorated Service


    [TransientService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }

    [ScopedService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }


    [SingletonService]
    public class DemoService
    {

        public void ShowTime()
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
    }


Decoreated service with interfaces

Provide one or more interface types


    [ScopedService(typeof(IWorker), typeof(IDriver))]
    public class WorkService : IWorker, IDriver
    {
        public void DoWork()
        {
            Console.WriteLine(nameof(this.DoWork));
        }

        public void Drive() => throw new NotImplementedException();
    }

Output registered types in STD out

DependencyInjectionSample project shows

Register Transient Services , Total: 1
     [ConcretType : SerivceTypes]
     (1) DemoService: DemoService
Register Scoped Services , Total: 1
     [ConcretType : SerivceTypes]
     (1) WorkService: WorkService, IWorker

Version History

Version Downloads Last updated
1.0.5 150 1/20/2019
1.0.4 133 1/16/2019
1.0.3 136 1/14/2019
1.0.0 130 1/11/2019