Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.1 KB

README.md

File metadata and controls

43 lines (30 loc) · 1.1 KB

ServiceLocator

Fill service provider with services marked by attributes

Installation

Install-Package ServiceLocator

Usage

Add Service locator

where T is a Assembly to scan

public void ConfigureServices(IServiceCollection services)
{
    // ****
    services.AddServiceLocator<Program>();
    // ****
}

Decorate class with attributes, so that locator can find them and register them in service provider.

  1. [Service(ServiceLifetime.Scoped)]
  2. [Service(ServiceLifetime.Singleton)]
  3. [Service(ServiceLifetime.Transient)]

Singleton means only a single instance will ever be created. That instance is shared between all components that require it. The same instance is thus used always.

Scoped means an instance is created once per scope. A scope is created on every request to the application, thus any components registered as Scoped will be created once per request.

Transient components are created every time they are requested and are never shared.

[Service(ServiceLifetime.Scoped)]
internal class ScopedScopedValueService : IScopedValueService
{
}