src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src/PACKAGE.md
Provides a suite of xUnit.net tests designed to ensure compatibility with the Microsoft.Extensions.DependencyInjection framework.
This package is intended for developers implementing their own Dependency Injection (DI) containers, allowing them to verify that their implementations conform to the expected behavior of the Microsoft Dependency Injection framework.
Microsoft.Extensions.DependencyInjection.Specification.Fakes) for testing common scenarios.To utilize the Microsoft.Extensions.DependencyInjection.Specification.Tests in a custom DI container implementation, create a test project and include this package as a dependency.
Then, run the specification tests against the DI container to validate its compatibility with the Microsoft.Extensions.DependencyInjection framework.
Start by creating a test project to run the specification tests.
Add the following NuGet packages to the test project:
Add the custom DI container package (e.g., MyCustomDI)
In the test project, create a class that inherits from DependencyInjectionSpecificationTests provided by the Microsoft.Extensions.DependencyInjection.Specification.Tests package.
Override the CreateServiceProvider method to return an instance of the DI container's service provider.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Specification.Tests;
using Xunit;
using MyCustomDI;
public class MyCustomDIContainerTests : DependencyInjectionSpecificationTests
{
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
{
// Create an instance of your custom DI container and build the service provider
return MyCustomDIContainer.BuildServiceProvider(serviceCollection);
}
}
Run the tests to validate that the custom DI container behaves according to the Microsoft Dependency Injection specifications.
The main types provided by this library are:
Microsoft.Extensions.DependencyInjection.Specification.DependencyInjectionSpecificationTestsMicrosoft.Extensions.DependencyInjection.Specification.KeyedDependencyInjectionSpecificationTestsMicrosoft.Extensions.DependencyInjection.Specification.Tests is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.