feat: Assembly-wide UseStaticMapper#2088
Merged
Merged
Conversation
faddiv
force-pushed
the
feature/assembly-wide-UseStaticMapper
branch
from
December 29, 2025 10:25
737b486 to
648e1bd
Compare
faddiv
commented
Dec 29, 2025
There was a problem hiding this comment.
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.
latonz
requested changes
Dec 29, 2025
latonz
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this contribution, I added my feedback and also copilot added some feedback.
latonz
approved these changes
Dec 30, 2025
…prove test coverage for self-referencing mappers
latonz
force-pushed
the
feature/assembly-wide-UseStaticMapper
branch
from
December 30, 2025 16:00
457ed78 to
386db69
Compare
Contributor
|
Thanks for this contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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