Skip to content

Commit dc79d70

Browse files
eNeRGy164jtschuster
authored andcommitted
Provide System.Composition.Convention package readme (dotnet#106782)
* Provide System.Composition.Convention package readme * Improve after feedback
1 parent 017ef35 commit dc79d70

File tree

2 files changed

+98
-10
lines changed

2 files changed

+98
-10
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
## About
2+
3+
<!-- A description of the package and where one can find more documentation -->
4+
5+
`System.Composition.Convention` 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 simplifies the process of applying consistent patterns for part exports, imports, and metadata by using convention-based configurations.
8+
It is useful for scenarios where you want to avoid repetitive attribute-based decoration and instead define conventions for registering types in your composition container.
9+
10+
## Key Features
11+
12+
<!-- The key features of this package -->
13+
14+
* Configure exports, imports, and metadata for parts using conventions rather than attributes.
15+
* Allows defining conventions through a fluent API, making configuration more flexible and readable.
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+
Configure parts for composition without using attributes.
22+
23+
```csharp
24+
using System.Composition.Convention;
25+
using System.Composition.Hosting;
26+
27+
var conventions = new ConventionBuilder();
28+
29+
// Apply conventions: any class that implements ILogger will be exported as ILogger
30+
conventions
31+
.ForTypesDerivedFrom<ILogger>()
32+
.Export<ILogger>();
33+
34+
var configuration = new ContainerConfiguration()
35+
.WithPart<FileLogger>(conventions)
36+
.WithPart<ConsoleLogger>(conventions);
37+
38+
using CompositionHost container = configuration.CreateContainer();
39+
40+
var loggers = container.GetExports<ILogger>();
41+
42+
foreach (var logger in loggers)
43+
{
44+
logger.Log("Hello, World!");
45+
}
46+
// FileLogger: Hello, World!
47+
// ConsoleLogger: Hello, World!
48+
49+
public interface ILogger
50+
{
51+
void Log(string message);
52+
}
53+
54+
public class FileLogger : ILogger
55+
{
56+
public void Log(string message) => Console.WriteLine($"FileLogger: {message}");
57+
}
58+
59+
public class ConsoleLogger : ILogger
60+
{
61+
public void Log(string message) => Console.WriteLine($"ConsoleLogger: {message}");
62+
}
63+
```
64+
65+
## Main Types
66+
67+
<!-- The main types provided in this library -->
68+
69+
The main types provided by this library are:
70+
71+
* `System.Composition.Convention.ConventionBuilder`
72+
* `System.Composition.Convention.PartConventionBuilder`
73+
* `System.Composition.Convention.ParameterImportConventionBuilder`
74+
75+
## Additional Documentation
76+
77+
<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->
78+
79+
* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition.convention)
80+
* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/)
81+
82+
## Related Packages
83+
84+
<!-- The related packages associated with this package -->
85+
86+
* [System.Composition](https://www.nuget.org/packages/System.Composition)
87+
* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel)
88+
* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting)
89+
* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime)
90+
* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts)
91+
92+
## Feedback & Contributing
93+
94+
<!-- How to provide feedback on this package and contribute to it -->
95+
96+
System.Composition.Convention is released as open source under the [MIT license](https://licenses.nuget.org/MIT).
97+
Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@
66
<StrongNameKeyId>Microsoft</StrongNameKeyId>
77
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
88
<IsPackable>true</IsPackable>
9-
<PackageDescription>Provides types that support using Managed Extensibility Framework with a convention-based configuration model.
10-
11-
Commonly Used Types:
12-
System.Composition.Convention.ConventionBuilder
13-
System.Composition.Convention.ExportConventionBuilder
14-
System.Composition.Convention.ImportConventionBuilder
15-
System.Composition.Convention.PartConventionBuilder
16-
System.Composition.Convention.ParameterImportConventionBuilder</PackageDescription>
9+
<PackageDescription>Provides types that support using Managed Extensibility Framework (MEF) with a convention-based configuration model.</PackageDescription>
1710
<!-- TODO https://github.com/dotnet/runtime/issues/90400: Annotate for nullable reference types -->
1811
<Nullable>disable</Nullable>
1912
<NoWarn>$(NoWarn);nullable</NoWarn>
20-
<!-- TODO: Add package README file: https://github.com/dotnet/runtime/issues/99358 -->
21-
<EnableDefaultPackageReadmeFile>false</EnableDefaultPackageReadmeFile>
2213
</PropertyGroup>
2314

2415
<ItemGroup>

0 commit comments

Comments
 (0)