Skip to content

Dependency Injection

Ian Johnson edited this page Sep 22, 2022 · 1 revision

Dependency Injection Container

Hardened uses the Microsoft.Extensions.DependencyInjection container.

Expose

Classes attributed with the Expose attribute the class will be registered with the dependency injection container. If no type is specified it will be registered by interface if available otherwise it will be concrete instance.

Singleton

Classes attributed with Singleton will be registered as singletons.

Scoped

Classes attributed with Scoped will be registered as scoped.

RegisterDependencies

Sometimes it's useful to register dependencies directly vs. using Attributes. To support this use case you can create a RegisterDependencies method in your HardenedStartup class

[HardenedStartup]
public class Application
{  
  private void RegisterDependencies(IEnvironment environment, IServiceCollection collection)
  {

  }
}

Clone this wiki locally