-
-
Notifications
You must be signed in to change notification settings - Fork 201
feat: Assembly-wide UseStaticMapper #2088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Assembly-wide UseStaticMapper #2088
Conversation
737b486 to
648e1bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables the UseStaticMapper attribute to be applied at the assembly level, making specified static mapper classes available globally to all mappers within the assembly without requiring explicit per-mapper configuration.
- Added assembly-level support for
UseStaticMapperattribute (both generic and non-generic variants) - Implemented filtering to prevent self-referencing mapper issues
- Restructured external mappings extraction logic to support global static mappers
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
src/Riok.Mapperly.Abstractions/UseStaticMapperAttribute.cs |
Updated AttributeUsage to allow assembly-level application |
src/Riok.Mapperly/MapperGenerator.cs |
Added BuildStaticMappers method and integrated global static mappers into descriptor building |
src/Riok.Mapperly/SyntaxProvider.cs |
Added GetUseStaticMapperDeclarations to collect assembly-level attributes |
src/Riok.Mapperly/Descriptors/DescriptorBuilder.cs |
Added global static mappers parameter and passed it to external mappings extraction |
src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs |
Refactored to handle both global and class-level static mappers |
src/Riok.Mapperly/Descriptors/UserMethodMappingExtractor.cs |
Added self-referencing mapper check to prevent circular dependencies |
test/Riok.Mapperly.Tests/Mapping/UseStaticMapperTest.cs |
Added comprehensive tests for assembly-level attribute usage |
test/Riok.Mapperly.IntegrationTests/Mapper/GlobalMappers.cs |
New mapper class to demonstrate assembly-level attribute usage |
test/Riok.Mapperly.IntegrationTests/Mapper/UseExternalMapper.cs |
Added test method for globally mapped types |
test/Riok.Mapperly.IntegrationTests/UseExternalMapperTest.cs |
Added integration test for global mapping functionality |
test/Riok.Mapperly.IntegrationTests/Models/GloballyMappedModel*.cs |
New model classes for testing global mappings |
test/Riok.Mapperly.IntegrationTests/Dto/GloballyMappedDto*.cs |
New DTO classes for testing global mappings |
test/Riok.Mapperly.IntegrationTests/_snapshots/*.verified.cs |
Updated snapshots with generated code for global mappings |
test/Riok.Mapperly.Abstractions.Tests/_snapshots/PublicApiTest.*.verified.cs |
Updated public API snapshots reflecting attribute changes |
docs/docs/configuration/external-mappings.mdx |
Added documentation section for globally available external mappers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...pperly.IntegrationTests/_snapshots/UseExternalMapperTest.SnapshotGeneratedSource.verified.cs
Show resolved
Hide resolved
...IntegrationTests/_snapshots/UseExternalMapperTest.SnapshotGeneratedSource_NET8_0.verified.cs
Show resolved
Hide resolved
latonz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution, I added my feedback and also copilot added some feedback.
src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs
Show resolved
Hide resolved
…prove test coverage for self-referencing mappers
457ed78 to
386db69
Compare
|
Thanks for this contribution! |
Assembly-wide UseStaticMapper
Description
This PR makes the UseStaticMapper attribute usable at the assembly level, so the specified mappers are available for all other mappers without needing to be specified explicitly.
Remarks
ImmutableArray<UseStaticMapperConfiguration> _globalStaticMappers;I considered passing it to the Build method. Does that make more sense? But if yes, then some other input also, which is not a dependency but a parameter.AttributeDataAccessor.Access<UseStaticMapperAttribute<object>, UseStaticMapperConfiguration>(attributeData);also processes the non-generic variant, so I left it this way.ExternalMappingsExtractorto better fit this new feature.Fixes #1146
Checklist