Provides a version of the Managed Extensibility Framework (MEF) that is lightweight and specifically optimized for high throughput scenarios, such as the web.
$ dotnet add package System.CompositionProvides the Managed Extensibility Framework (MEF) 2.0, a lightweight, attribute-driven Dependency Injection (DI) container.
MEF simplifies the composition of applications by allowing components to be loosely coupled and dynamically discovered. This package supports the development of modular and maintainable applications by enabling parts to be composed at runtime.
Running code from a discovered component.
using System.Composition;
using System.Composition.Hosting;
var configuration = new ContainerConfiguration().WithPart<Service>();
using var container = configuration.CreateContainer();
var service = container.GetExport<Service>();
service.Execute();
// Output: Service is running!
[Export]
public class Service
{
public void Execute() => Console.WriteLine("Service is running!");
}
The main types provided by this library are:
System.Composition.ExportAttributeSystem.Composition.ImportAttributeSystem.Composition.Convention.ConventionBuilderSystem.Composition.Hosting.CompositionHostSystem.Composition.CompositionContextSystem.Composition.CompositionContextExtensionsSystem.Composition is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.