Skip to content

Free user from ioc attributes: add arguments: GenericFactoryTypeMapping, InjectMembers#7

Merged
AndyElessar merged 11 commits intomainfrom
free-user-from-ioc-attributes
Mar 3, 2026
Merged

Free user from ioc attributes: add arguments: GenericFactoryTypeMapping, InjectMembers#7
AndyElessar merged 11 commits intomainfrom
free-user-from-ioc-attributes

Conversation

@AndyElessar
Copy link
Copy Markdown
Owner

Description

Free user from ioc attributes for SourceGen.Ioc 1.0.0 release.

  • IocRegisterForAttribute add arguments: GenericFactoryTypeMapping, InjectMembers.
  • IocRegisterDefaultsAttribute add argument: GenericFactoryTypeMapping

Related Issue

Implement #6

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Checklist

  • My code follows the project's coding guidelines
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • I have added XML documentation for public APIs

Testing

Test is all pass.

…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.
Copilot AI review requested due to automatic review settings March 2, 2026 21:21
@AndyElessar AndyElessar linked an issue Mar 2, 2026 that may be closed by this pull request
3 tasks
Copy link
Copy Markdown

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 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 InjectMembers to IocRegisterForAttribute and 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.

Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Outdated
Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Outdated
Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Outdated
Comment thread .github/agents/Orchestrator.agent.md Outdated
Comment thread src/Ioc/src/SourceGen.Ioc/IocRegisterForAttribute.cs Outdated
Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/Spec/SPEC.md Outdated
Copy link
Copy Markdown

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

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Outdated
Copy link
Copy Markdown

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

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Comment thread docs/Ioc/04_Field_Property_Method_Injection.md Outdated
Comment thread docs/Ioc/08_Factory_Instance.md Outdated
Copy link
Copy Markdown

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

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.cs Outdated
Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/AnalyzerReleases.Unshipped.md Outdated
Copy link
Copy Markdown

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

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Comment thread src/Ioc/src/SourceGen.Ioc/IocRegisterForAttribute.cs Outdated
Comment thread src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Outdated
@AndyElessar AndyElessar merged commit 40a57c8 into main Mar 3, 2026
5 checks passed
@AndyElessar AndyElessar deleted the free-user-from-ioc-attributes branch March 28, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Free user from IocGenericFactoryAttribute, IocInjectAttribute

2 participants