Skip to content

Commit 7fc56b8

Browse files
authored
Provide System.Composition.Runtime package readme (#106784)
* Provide System.Composition.Runtime package readme * Improve after feedback
1 parent 389f3b2 commit 7fc56b8

File tree

2 files changed

+88
-6
lines changed

2 files changed

+88
-6
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## About
2+
3+
<!-- A description of the package and where one can find more documentation -->
4+
5+
`System.Composition.Runtime` is part of the Managed Extensibility Framework (MEF) 2.0, a composition library for .NET that enables dependency injection through attributes or conventions.
6+
7+
This package enables the discovery and composition of parts in applications using MEF 2.0.
8+
It offers the runtime implementation needed for managing composable parts, resolving dependencies, and dynamically wiring components together.
9+
10+
## Key Features
11+
12+
<!-- The key features of this package -->
13+
14+
* Facilitates runtime discovery and composition of parts.
15+
16+
## How to Use
17+
18+
<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->
19+
20+
Resolve dependencies on the fly and can be useful for dynamically loaded components or plugins.
21+
22+
```csharp
23+
using System.Composition;
24+
using System.Composition.Hosting;
25+
26+
var configuration = new ContainerConfiguration()
27+
.WithPart<Service>();
28+
29+
using CompositionHost container = configuration.CreateContainer();
30+
31+
var consumer = new Consumer(container);
32+
consumer.Execute();
33+
// Service is running.
34+
35+
public interface IService
36+
{
37+
void Run();
38+
}
39+
40+
[Export(typeof(IService))]
41+
public class Service : IService
42+
{
43+
public void Run() => Console.WriteLine("Service is running.");
44+
}
45+
46+
public class Consumer(CompositionContext context)
47+
{
48+
public void Execute()
49+
{
50+
// Use the context to resolve the service
51+
var service = context.GetExport<IService>();
52+
service.Run();
53+
}
54+
}
55+
```
56+
57+
## Main Types
58+
59+
<!-- The main types provided in this library -->
60+
61+
The main type provided by this library is:
62+
63+
* `System.Composition.CompositionContext`
64+
65+
## Additional Documentation
66+
67+
<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->
68+
69+
* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition.compositioncontext)
70+
* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/)
71+
72+
## Related Packages
73+
74+
<!-- The related packages associated with this package -->
75+
76+
* [System.Composition](https://www.nuget.org/packages/System.Composition)
77+
* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel)
78+
* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention)
79+
* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting)
80+
* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts)
81+
82+
## Feedback & Contributing
83+
84+
<!-- How to provide feedback on this package and contribute to it -->
85+
86+
System.Composition.Runtime is released as open source under the [MIT license](https://licenses.nuget.org/MIT).
87+
Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77
<StrongNameKeyId>Microsoft</StrongNameKeyId>
88
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
99
<IsPackable>true</IsPackable>
10-
<PackageDescription>Contains runtime components of the Managed Extensibility Framework.
11-
12-
Commonly Used Types:
13-
System.Composition.CompositionContext</PackageDescription>
10+
<PackageDescription>Contains runtime components of the Managed Extensibility Framework (MEF).</PackageDescription>
1411
<!-- TODO https://github.com/dotnet/runtime/issues/90400: Annotate for nullable reference types -->
1512
<Nullable>disable</Nullable>
1613
<NoWarn>$(NoWarn);nullable</NoWarn>
17-
<!-- TODO: Add package README file: https://github.com/dotnet/runtime/issues/99358 -->
18-
<EnableDefaultPackageReadmeFile>false</EnableDefaultPackageReadmeFile>
1914
</PropertyGroup>
2015

2116
<ItemGroup>

0 commit comments

Comments
 (0)