Skip to content

Conversation

@faddiv
Copy link
Contributor

@faddiv faddiv commented Dec 29, 2025

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

  • I thought this would be a useful feature while working with Mapperly, then I saw there is already an open issue for this, so I implemented it. 🙂
  • Instead of 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.
  • A little bit restructured the methods in ExternalMappingsExtractor to better fit this new feature.
  • The integration test on the generic variant was removed in the end. This way, no conditional compilations are needed.

Fixes #1146

Checklist

  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

@faddiv faddiv force-pushed the feature/assembly-wide-UseStaticMapper branch from 737b486 to 648e1bd Compare December 29, 2025 10:25
Copy link

Copilot AI left a 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 UseStaticMapper attribute (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.

Copy link
Contributor

@latonz latonz left a 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.

@latonz latonz added the enhancement New feature or request label Dec 30, 2025
@latonz latonz changed the title Assembly-wide UseStaticMapper feat: Assembly-wide UseStaticMapper Dec 30, 2025
@latonz latonz force-pushed the feature/assembly-wide-UseStaticMapper branch from 457ed78 to 386db69 Compare December 30, 2025 16:00
@latonz latonz merged commit 646f9ee into riok:main Dec 30, 2025
17 checks passed
@latonz
Copy link
Contributor

latonz commented Dec 30, 2025

Thanks for this contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow assembly-wide usage of UseStaticMapper

2 participants