Overview

This namespace provides fundamental interfaces and classes for implementing a .NET Dependency Injection container. It defines how services can be registered and resolved.

Key components include:

  • IServiceCollection: Represents a collection of service descriptors that can be used to configure a dependency injection container.
  • IServiceProvider: Represents a service locator that can be used to resolve services.
  • ServiceDescriptor: Describes a service registration in an IServiceCollection.
  • ServiceLifetime: Specifies the lifetime of a registered service.

Classes and Interfaces

Interface IServiceCollection

Defines the contract for a collection of service descriptors. This is the primary interface used to register services with the dependency injection container.

public interface IServiceCollection : IEnumerable<ServiceDescriptor>

Methods

Interface IServiceProvider

Defines the contract for a service locator that can be used to resolve services. It is the root of the service resolution graph.

public interface IServiceProvider

Methods

Class ServiceCollection

A concrete implementation of IServiceCollection, providing a mutable collection of service descriptors.

public class ServiceCollection : IServiceCollection

Constructors

Class ServiceProvider

A concrete implementation of IServiceProvider that builds a service resolution graph from a collection of service descriptors.

public class ServiceProvider : IServiceProvider, IDisposable

Methods

Class ServiceDescriptor

Represents a descriptor for a service registration. It includes the service type, implementation type or factory, and the service lifetime.

public sealed class ServiceDescriptor

Properties

  • ImplementationFactory
  • ImplementationInstance
  • ImplementationType
  • ServiceType
  • Lifetime

Methods

Enum ServiceLifetime

Specifies the lifetime of a registered service.

public enum ServiceLifetime

Members

  • Transient: A new instance of the service is provided every time an instance is requested.
  • Scoped: A new instance of the service is provided for each scope.
  • Singleton: A single instance of the service is provided every time an instance is requested.
Class ActivatorUtilities

Provides utility methods for activating objects and creating closures that resolve services from an IServiceProvider.

public static class ActivatorUtilities

Methods

Class ServiceCollectionExtensions

Extension methods for IServiceCollection to simplify common service registration scenarios.

public static class ServiceCollectionExtensions

Methods