Skip to content

Commit 6e68f92

Browse files
authored
Provide System.Composition.TypedParts package readme (#106785)
* Provide System.Composition.TypedParts package readme * Improve after feedback
1 parent 7fc56b8 commit 6e68f92

File tree

2 files changed

+89
-7
lines changed

2 files changed

+89
-7
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## About
2+
3+
<!-- A description of the package and where one can find more documentation -->
4+
5+
`System.Composition.TypedParts` 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+
Provides `ContainerConfiguration` and some extension methods for the Managed Extensibility Framework (MEF).
8+
9+
## Key Features
10+
11+
<!-- The key features of this package -->
12+
13+
* Provides container configuration.
14+
15+
## How to Use
16+
17+
<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->
18+
19+
Register parts from an entire assembly.
20+
21+
```csharp
22+
using System.Composition;
23+
using System.Composition.Hosting;
24+
using System.Reflection;
25+
26+
// Register all parts from the current assembly
27+
var configuration = new ContainerConfiguration()
28+
.WithAssembly(Assembly.GetExecutingAssembly());
29+
30+
using CompositionHost container = configuration.CreateContainer();
31+
32+
var handlers = container.GetExports<IHandler>();
33+
foreach (var handler in handlers)
34+
{
35+
handler.Handle();
36+
}
37+
// HandlerA is handling.
38+
// HandlerB is handling.
39+
40+
public interface IHandler
41+
{
42+
void Handle();
43+
}
44+
45+
[Export(typeof(IHandler))]
46+
public class HandlerA : IHandler
47+
{
48+
public void Handle() => Console.WriteLine("HandlerA is handling.");
49+
}
50+
51+
[Export(typeof(IHandler))]
52+
public class HandlerB : IHandler
53+
{
54+
public void Handle() => Console.WriteLine("HandlerB is handling.");
55+
}
56+
```
57+
58+
## Main Types
59+
60+
<!-- The main types provided in this library -->
61+
62+
The main types provided by this library are:
63+
64+
* `System.Composition.Hosting.ContainerConfiguration`
65+
* `System.Composition.CompositionContextExtensions`
66+
67+
## Additional Documentation
68+
69+
<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->
70+
71+
* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/)
72+
73+
## Related Packages
74+
75+
<!-- The related packages associated with this package -->
76+
77+
* [System.Composition](https://www.nuget.org/packages/System.Composition)
78+
* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel)
79+
* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention)
80+
* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting)
81+
* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime)
82+
83+
## Feedback & Contributing
84+
85+
<!-- How to provide feedback on this package and contribute to it -->
86+
87+
System.Composition.TypedParts is released as open source under the [MIT license](https://licenses.nuget.org/MIT).
88+
Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@
88
<StrongNameKeyId>Microsoft</StrongNameKeyId>
99
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
1010
<IsPackable>true</IsPackable>
11-
<PackageDescription>Provides some extension methods for the Managed Extensibility Framework.
12-
13-
Commonly Used Types:
14-
System.Composition.CompositionContextExtensions
15-
System.Composition.Hosting.ContainerConfiguration</PackageDescription>
11+
<PackageDescription>Provides container configuration and some extension methods for the Managed Extensibility Framework (MEF).</PackageDescription>
1612
<!-- TODO https://github.com/dotnet/runtime/issues/90400: Annotate for nullable reference types -->
1713
<Nullable>disable</Nullable>
1814
<NoWarn>$(NoWarn);nullable</NoWarn>
19-
<!-- TODO: Add package README file: https://github.com/dotnet/runtime/issues/99358 -->
20-
<EnableDefaultPackageReadmeFile>false</EnableDefaultPackageReadmeFile>
2115
</PropertyGroup>
2216

2317
<ItemGroup>

0 commit comments

Comments
 (0)