You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,9 @@ In modern applications following Clean or Onion Architecture, mapping objects be
26
26
27
27
***Custom Mapping Policies**: A powerful fluent API (`ConfigureMappingPolicies`) lets you override the default behavior for creating objects and mapping individual properties and constructor parameters.
28
28
29
-
***Dependency Injection Integration**: Provides `AddMappers()` and `IMapperResolver` for easy registration and resolution of mappers in your application's DI container.
29
+
***Dependency Injection Integration**: Provides `AddGeneratedMappers()` for high-performance, reflection-free registration of mappers.
30
+
31
+
***Cross-Assembly Discovery**: Easily register mappers across multiple projects using the `[assembly: DiscoverMappers]` attribute.
30
32
31
33
***Nested & Collection Mapping**: Automatically discovers and uses other mappers for complex, nested objects and collections.
32
34
@@ -48,7 +50,9 @@ The core of ProjectR is a Roslyn Source Generator that activates during compilat
48
50
49
51
* If it finds a static method named `ConfigureMappingPolicies(IPolicyConfiguration config)`, it parses the user-defined rules and applies them to override the default behavior.
50
52
51
-
4.**Code Generation**: It generates a `partial class` implementation in a `.g.cs` file containing the `ProjectGenerated` and `BuildGenerated` methods. The public `Project` and `Build` methods in your base class then call these generated implementations. This generated code is compiled along with the rest of your project.
53
+
4.**Code Generation**: It generates:
54
+
* A `partial class` implementation in a `.g.cs` file containing the `ProjectGenerated` and `BuildGenerated` methods.
55
+
* A `GeneratedMapperRegistrations` class containing an `AddGeneratedMappers()` extension method for `IServiceCollection`. This method registers all mappers in the assembly directly into the DI container without using reflection.
52
56
53
57
## 🚀 Getting Started: Example
54
58
@@ -134,26 +138,29 @@ public partial class CreateProductDtoMapper
134
138
135
139
### 3. Configure Dependency Injection
136
140
137
-
In your `Program.cs`, use the `AddMappers` extension method to scan your assemblies and register all found mappers.
141
+
In your `Program.cs`, call `AddGeneratedMappers()` to register all mappers. To discover mappers from referenced assemblies, add the `[assembly: DiscoverMappers]` attribute to your assembly.
138
142
139
143
```csharp
140
144
// Program.cs
141
-
usingProjectR.Hosting;
142
-
usingYourApp.Application.DTOs; // The assembly containing your DTOs
145
+
usingProjectR.Generated; // The namespace where registrations are generated
146
+
147
+
[assembly: DiscoverMappers] // Enable discovery of mappers in referenced projects
143
148
144
149
varbuilder=WebApplication.CreateBuilder(args);
145
150
146
151
// ... other services
147
152
148
-
//Scan the specified assembly for mappers and register them and the resolver.
0 commit comments