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 anIServiceCollection.ServiceLifetime: Specifies the lifetime of a registered service.
Classes and Interfaces
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
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
A concrete implementation of IServiceCollection, providing a mutable collection of service descriptors.
public class ServiceCollection : IServiceCollection
Constructors
A concrete implementation of IServiceProvider that builds a service resolution graph from a collection of service descriptors.
public class ServiceProvider : IServiceProvider, IDisposable
Methods
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
ImplementationFactoryImplementationInstanceImplementationTypeServiceTypeLifetime
Methods
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.
Provides utility methods for activating objects and creating closures that resolve services from an IServiceProvider.
public static class ActivatorUtilities
Methods
Extension methods for IServiceCollection to simplify common service registration scenarios.
public static class ServiceCollectionExtensions