|
| 1 | +## About |
| 2 | + |
| 3 | +<!-- A description of the package and where one can find more documentation --> |
| 4 | + |
| 5 | +Provides the Managed Extensibility Framework (MEF) 2.0, a lightweight, attribute-driven Dependency Injection (DI) container. |
| 6 | + |
| 7 | +MEF simplifies the composition of applications by allowing components to be loosely coupled and dynamically discovered. |
| 8 | +This package supports the development of modular and maintainable applications by enabling parts to be composed at runtime. |
| 9 | + |
| 10 | +## Key Features |
| 11 | + |
| 12 | +<!-- The key features of this package --> |
| 13 | + |
| 14 | +* Components are discovered and composed using attributes. |
| 15 | +* Provides dependency injection capabilities for loosely coupled modules. |
| 16 | + |
| 17 | +## How to Use |
| 18 | + |
| 19 | +<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package --> |
| 20 | + |
| 21 | +Running code from a discovered component. |
| 22 | + |
| 23 | +```csharp |
| 24 | +using System.Composition; |
| 25 | +using System.Composition.Hosting; |
| 26 | + |
| 27 | +var configuration = new ContainerConfiguration().WithPart<Service>(); |
| 28 | + |
| 29 | +using var container = configuration.CreateContainer(); |
| 30 | + |
| 31 | +var service = container.GetExport<Service>(); |
| 32 | +service.Execute(); |
| 33 | +// Output: Service is running! |
| 34 | +
|
| 35 | +[Export] |
| 36 | +public class Service |
| 37 | +{ |
| 38 | + public void Execute() => Console.WriteLine("Service is running!"); |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Main Types |
| 43 | + |
| 44 | +<!-- The main types provided in this library --> |
| 45 | + |
| 46 | +The main types provided by this library are: |
| 47 | + |
| 48 | +* `System.Composition.ExportAttribute` |
| 49 | +* `System.Composition.ImportAttribute` |
| 50 | +* `System.Composition.Convention.ConventionBuilder` |
| 51 | +* `System.Composition.Hosting.CompositionHost` |
| 52 | +* `System.Composition.CompositionContext` |
| 53 | +* `System.Composition.CompositionContextExtensions` |
| 54 | + |
| 55 | +## Additional Documentation |
| 56 | + |
| 57 | +<!-- Links to further documentation. Remove conceptual documentation if not available for the library. --> |
| 58 | + |
| 59 | +* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition) |
| 60 | +* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/) |
| 61 | + |
| 62 | +## Related Packages |
| 63 | + |
| 64 | +<!-- The related packages associated with this package --> |
| 65 | + |
| 66 | +* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel) |
| 67 | +* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention) |
| 68 | +* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting) |
| 69 | +* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime) |
| 70 | +* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts) |
| 71 | + |
| 72 | +## Feedback & Contributing |
| 73 | + |
| 74 | +<!-- How to provide feedback on this package and contribute to it --> |
| 75 | + |
| 76 | +System.Composition is released as open source under the [MIT license](https://licenses.nuget.org/MIT). |
| 77 | +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). |
0 commit comments