Free user from ioc attributes: add arguments: GenericFactoryTypeMapping, InjectMembers#7
Merged
AndyElessar merged 11 commits intomainfrom Mar 3, 2026
Merged
Conversation
…and InjectMembers properties ( #6 ) - Added GenericFactoryTypeMapping property to IocRegisterForAttribute and IocRegisterForAttribute<T> for better factory method type mapping. - Introduced InjectMembers property to specify members for dependency injection, allowing for flexible injection configurations. - Implemented tests for new features, ensuring correct behavior of GenericFactoryTypeMapping and InjectMembers in various scenarios. - Added diagnostics for invalid InjectMembers formats, ensuring robust error handling and user guidance. - Updated snapshot tests to validate generated code for new injection scenarios, including keyed and multiple member injections.
3 tasks
There was a problem hiding this comment.
Pull request overview
This PR extends SourceGen.Ioc’s registration attributes so consumers can opt into generic factory mapping and member injection configuration from the registration site, reducing the need to annotate third-party/service types directly—targeting the 1.0.0 DX goal (“free user from ioc attributes”).
Changes:
- Add
GenericFactoryTypeMapping(factory generic type mapping) to registration attributes and wire it into factory resolution + SGIOC016 behavior. - Add
InjectMemberstoIocRegisterForAttributeand implement generator parsing + new analyzer diagnostics (SGIOC023/SGIOC024) for validation. - Add snapshot/analyzer tests and update docs/spec/changelog to describe the new capabilities.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Ioc/src/SourceGen.Ioc/IocRegisterForAttribute.cs | Adds InjectMembers + GenericFactoryTypeMapping public API and docs. |
| src/Ioc/src/SourceGen.Ioc/IocRegisterDefaultsAttribute.cs | Adds GenericFactoryTypeMapping public API. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/TransformExtensions.cs | Extracts GenericFactoryTypeMapping from attribute properties as a fallback for generic factories. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs | Parses/merges InjectMembers into injection member generation. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.cs | Introduces SGIOC023/SGIOC024 descriptors and registers them. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.AttributeUsage.cs | Validates InjectMembers; suppresses SGIOC016 when mapping is present. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/Spec/SPEC.md | Updates analyzer spec for SGIOC016 and adds SGIOC023/SGIOC024 sections. |
| src/Ioc/src/SourceGen.Ioc.SourceGenerator/AnalyzerReleases.Unshipped.md | Documents SGIOC023/SGIOC024 additions. |
| src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/InjectMembersTests.cs | New snapshot tests for InjectMembers generation scenarios. |
| src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/*.verified.txt | New snapshot baselines for InjectMembers scenarios. |
| src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/FactoryAndInstanceTests.cs | Adds snapshot coverage for attribute-provided generic factory mapping. |
| src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/*.verified.txt | Baseline for the new generic factory mapping snapshot. |
| src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC023Tests.cs | New analyzer tests for invalid InjectMembers element formats. |
| src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC024Tests.cs | New analyzer tests for non-injectable InjectMembers targets. |
| src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC016Tests.cs | Extends SGIOC016 tests to cover mapping-on-attribute suppression. |
| src/Ioc/test/SourceGen.Ioc.Test/Helpers/Constants.cs | Adds test category constants for InjectMembers and new diagnostics. |
| docs/Ioc/08_Factory_Instance.md | Documents generic factory mapping via GenericFactoryTypeMapping on attributes. |
| docs/Ioc/04_Field_Property_Method_Injection.md | Documents InjectMembers + new diagnostics SGIOC023/SGIOC024. |
| .github/copilot-instructions.md | Updates design priorities ordering (performance vs incremental performance). |
| .github/agents/Orchestrator.agent.md | Updates tool list configuration for the orchestrator agent. |
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.
Description
Free user from ioc attributes for SourceGen.Ioc 1.0.0 release.
IocRegisterForAttributeadd arguments:GenericFactoryTypeMapping,InjectMembers.IocRegisterDefaultsAttributeadd argument:GenericFactoryTypeMappingRelated Issue
Implement #6
Type of Change
Checklist
Testing
Test is all pass.