nug Createrun NuGet

Microsoft.Extensions.DependencyInjection

10.0.7 122 download(s)
public

Default implementation of dependency injection for Microsoft.Extensions.DependencyInjection.

PackageReference
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
.NET CLI
dotnet add package Microsoft.Extensions.DependencyInjection --version 10.0.7

Dependencies

net10.0
Package Version range
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )
net462
Package Version range
Microsoft.Bcl.AsyncInterfaces [10.0.7, )
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )
System.Threading.Tasks.Extensions [4.6.3, )
net8.0
Package Version range
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )
net9.0
Package Version range
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )
netstandard2.0
Package Version range
Microsoft.Bcl.AsyncInterfaces [10.0.7, )
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )
System.Threading.Tasks.Extensions [4.6.3, )
netstandard2.1
Package Version range
Microsoft.Extensions.DependencyInjection.Abstractions [10.0.7, )

Readme

## About
Supports the dependency injection (DI) software design pattern which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies.

## Key Features
Provides an implementation of the DI interfaces found in the `Microsoft.Extensions.DependencyInjection.Abstractions` package.

## How to Use
```cs
ServiceCollection services = new ();
services.AddSingleton<IMessageWriter, MessageWriter>();
using ServiceProvider provider = services.BuildServiceProvider();

// The code below, following the IoC pattern, is typically only aware of the IMessageWriter interface, not the implementation.
IMessageWriter messageWriter = provider.GetService<IMessageWriter>()!;
messageWriter.Write("Hello");

public interface IMessageWriter
{
    void Write(string message);
}

internal class MessageWriter : IMessageWriter
{
    public void Write(string message)
    {
        Console.WriteLine($"MessageWriter.Write(message: \"{message}\")");
    }
}
```

## Main Types
The main types provided by this library are:
* `Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory`
* `Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions`
* `Microsoft.Extensions.DependencyInjection.ServiceProvider`

## Additional Documentation
* [Conceptual documentation](https://learn.microsoft.com/dotnet/core/extensions/dependency-injection)
* API documentation
  - [DefaultServiceProviderFactory](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.defaultserviceproviderfactory)
  - [ServiceCollectionContainerBuilderExtensions](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.servicecollectioncontainerbuilderextensions)
  - [ServiceProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.serviceprovider)

## Related Packages
- `Microsoft.Extensions.DependencyInjection.Abstractions`
- `Microsoft.Extensions.Hosting`
- `Microsoft.Extensions.Options`

## Feedback & Contributing
Microsoft.Extensions.DependencyInjection is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

Versions

Target frameworks

net10.0 net462 net8.0 net9.0 netstandard2.0 netstandard2.1

Metadata

Published
Size
343 KB
Authors
Microsoft
License
MIT
Repository
https://github.com/dotnet/dotnet commit b16286c2284fecf303dbc12a0bb152476d662e44
Flags
SemVer 1
SHA512
7ufEXyrvD/MP3DHnIftNGKMhX4Oq+MhL9zGS/AwU2CmEbbrQNOsMs2t+38TYosNHO4eItFsIBmSNUU7dFdN1Ig==

Release notes

https://go.microsoft.com/fwlink/?LinkID=799421