Skip to content

Feature: async method inject#24

Merged
AndyElessar merged 12 commits intomainfrom
feature/async-method-inject
Apr 3, 2026
Merged

Feature: async method inject#24
AndyElessar merged 12 commits intomainfrom
feature/async-method-inject

Conversation

@AndyElessar
Copy link
Copy Markdown
Owner

Description

Implement feature: Async Method Inject, allow user to inject Task<T> and use [IocInject] on async method.
Also fix issue of when Container with ExplicitOnly, Lazy<T> / Func<T> / multi param Func<...> inner type is not in container will lead infinite recursion.

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

All existing tests and new test are pass.

AndyElessar and others added 7 commits March 28, 2026 05:32
…e incomplete

Add `IocContainerGlobalOptions`

Co-authored-by: Copilot <copilot@github.com>
refactor:  Add `IsAsyncInit` property avoid duplicate calculation
fix: Container with `ExplicitOnly` and `Lazy<T>` / `Func<T>` inner type is not in container, will lead infinite recursion

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings March 30, 2026 21:17
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

Adds Async Method Inject to SourceGen.Ioc so [IocInject] can be applied to Task-returning methods and consumers can inject Task<T> (with generator-produced async init paths). Also expands the test-case assembly and AOT test suite to cover wrapper/collection/tag/factory behaviors and documents the new feature + diagnostics.

Changes:

  • Add feature flag AsyncMethodInject and model/generator support for async-init services via Task<T> wrappers.
  • Extend analyzers/tests/specs/docs to cover async method injection semantics and new diagnostics IDs (SGIOC026–031).
  • Add broad test-case modules + AOT tests for wrappers, collections, tags, factories/instances, eager resolve, switch-statement resolver path, and open-generic discovery.

Reviewed changes

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

Show a summary per file
File Description
src/Ioc/test/SourceGen.Ioc.TestCase/Wrapper.cs Adds wrapper consumer/module for Lazy/Func wrapper regression coverage.
src/Ioc/test/SourceGen.Ioc.TestCase/TestCaseModule.cs Imports new test-case modules into the composite ExplicitOnly container.
src/Ioc/test/SourceGen.Ioc.TestCase/Tags.cs Adds tagged services + container for tags filtering tests.
src/Ioc/test/SourceGen.Ioc.TestCase/SourceGen.Ioc.TestCase.csproj Enables AsyncMethodInject feature flag for the test-case project.
src/Ioc/test/SourceGen.Ioc.TestCase/RegisterAllInterfaces.cs Adds RegisterAllInterfaces = true test module.
src/Ioc/test/SourceGen.Ioc.TestCase/OpenGeneric.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestCase/KeyedCollection.cs Adds keyed dictionary injection test module.
src/Ioc/test/SourceGen.Ioc.TestCase/Keyed.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestCase/Injection.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestCase/GlobalUsing.cs Introduces global usings for the TestCase project.
src/Ioc/test/SourceGen.Ioc.TestCase/Factory.cs Adds factory + instance registration test module.
src/Ioc/test/SourceGen.Ioc.TestCase/Decorator.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestCase/Collection.cs Adds collection injection test module.
src/Ioc/test/SourceGen.Ioc.TestCase/Basic.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestCase/AsyncInjection.cs Adds async-init service + container partial Task<T> accessor.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/WrapperTests.cs Adds AOT tests for Lazy/Func wrapper resolution (standalone + MS.DI).
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/ThreadSafeStrategyTests.cs Moves redundant usings to global usings setup.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/TagsTests.cs Adds AOT tests for IncludeTags filtering + unfiltered module behavior.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/SwitchStatementTests.cs Adds AOT tests for switch-statement resolver dispatch path.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/RegisterIntegrationTests.cs Adds cross-assembly integration tests for collections/factories/wrappers.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/RegisterAllInterfacesTests.cs Adds AOT tests for RegisterAllInterfaces behavior (standalone vs MS.DI).
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/KeyedCollectionTests.cs Adds AOT tests for keyed dictionary and keyed resolution; MS.DI dictionary test skipped for AOT.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/FactoryAndInstanceTests.cs Adds AOT tests for factory/instance registration behavior.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/EagerResolveTests.cs Adds AOT tests for eager singleton resolution behavior.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/CrossAssemblyAttributeTests.cs Cleans up unused using after global usings changes.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/ContainerTests.cs Adds open-generic discovery test + cleans up using directives.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/CollectionTests.cs Adds AOT tests for IEnumerable and keyed dictionary collection behavior.
src/Ioc/test/SourceGen.Ioc.TestAot/Tests/AsyncInjectionTests.cs Adds AOT tests for async-init via Task<T> and composite containers.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/ThreadSafeStrategyContainers.cs Cleans up unused usings in AOT container fixtures.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/SwitchStatementContainer.cs Adds test container configured with UseSwitchStatement = true.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/OpenGenericDiscovery.cs Cleans up unused usings in AOT open-generic discovery fixtures.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/FeatureServiceContainers.cs Adds test-only services/containers for IncludeTags compile-time filtering.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/EagerResolveContainer.cs Adds test container configured with eager resolve options.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/ContainerModule.cs Cleans up unused usings in the main AOT container module.
src/Ioc/test/SourceGen.Ioc.TestAot/TestCase/AsyncInjectionContainer.cs Adds composite container importing Injection + AsyncInjection modules.
src/Ioc/test/SourceGen.Ioc.TestAot/SourceGen.Ioc.TestAot.csproj Enables AsyncMethodInject feature flag for AOT test project.
src/Ioc/test/SourceGen.Ioc.TestAot/GlobalUsing.cs Introduces global usings for AOT test project.
src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/AsyncMethodInjectTests.cs Adds snapshot tests for register-path async injection + Task wrapper behaviors.
src/Ioc/test/SourceGen.Ioc.Test/RegisterSourceGeneratorSnapshot/*.verified.txt Adds verified snapshots for register-path async-init outputs.
src/Ioc/test/SourceGen.Ioc.Test/Helpers/Constants.cs Adds constants for AsyncMethodInject + new diagnostic IDs.
src/Ioc/test/SourceGen.Ioc.Test/ContainerSourceGeneratorSnapshot/WrapperTypeDependencyTests*.verified.txt Adds verified snapshots for ExplicitOnly Func-wrapper recursion regression.
src/Ioc/test/SourceGen.Ioc.Test/ContainerSourceGeneratorSnapshot/WrapperTypeDependencyTests.cs Adds regression tests for ExplicitOnly wrapper fallback behavior.
src/Ioc/test/SourceGen.Ioc.Test/ContainerSourceGeneratorSnapshot/AsyncMethodInjectTests*.verified.txt Adds verified snapshots for container-path async-init generation + disposal patterns.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC031Tests.cs Adds analyzer tests for async-void inject methods diagnostic behavior.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC030Tests.cs Adds deferred analyzer tests documenting future SGIOC030 behavior.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC029Tests.cs Adds deferred analyzer tests documenting future SGIOC029 behavior.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC027Tests.cs Adds deferred analyzer tests documenting future SGIOC027 behavior.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC026Tests.cs Adds analyzer tests for invalid feature combinations (AsyncMethodInject requires MethodInject).
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC022Tests.cs Extends feature-gate analyzer tests for MethodInject vs AsyncMethodInject scenarios.
src/Ioc/test/SourceGen.Ioc.Test/Analyzer/SGIOC007Tests.cs Updates return-type validation tests to align with new feature-gating behavior.
src/Ioc/src/SourceGen.Ioc/IocContainerGlobalOptions.cs Adds global disposal exception hook for Task-backed cached services.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/RoslynExtensions.cs Adds helper to detect non-generic Task return type for async inject methods.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/TypeData.cs Introduces TaskTypeData and WrapperKind.Task for Task wrapper support.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/TransformExtensions.cs Adds wrapper-kind mapping for Task and allows Task-returning inject methods in member enumeration.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/IocFeatures.cs Adds AsyncMethodInject feature flag and feature parsing/mapping.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/InjectionMemberData.cs Adds InjectionMemberType.AsyncMethod.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/ContainerWithGroups.cs Extends cached registration metadata with IsAsyncInit.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/TransformRegister.cs Classifies Task-returning inject methods as AsyncMethod + orders injection stages.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/SPEC.spec.md Updates overall spec index for async injection + Task wrapper.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/Register.Injection.spec.md Defines AsyncMethodInject behavior, ordering, and Task wrapper rules.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/Container.ThreadSafety.spec.md Specifies async-init thread-safety strategy override rules.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/Container.Injection.spec.md Specifies container async-init resolution and Task disposal semantics.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/Container.Basic.spec.md Updates container spec example to mention Task-backed disposal overloads.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/LazyRegistrationHelper.cs Excludes async-init services from Lazy resolver entries.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/GroupRegistrationsForContainer.cs Excludes async-init regs from collections + eager resolve; tracks IsAsyncInit.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/FuncRegistrationHelper.cs Excludes async-init services from Func resolver entries.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/AnalyzerReleases.Unshipped.md Documents new diagnostics SGIOC026–031.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/Spec/SPEC.spec.md Updates analyzer spec for async injection return types and new diagnostics.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.cs Adds new diagnostic descriptors and compilation-end validation for feature combos.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.AttributeUsage.cs Adds SGIOC031 handling + async Task inject-method gating/validation.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/ContainerAnalyzer.cs Adds diagnostic descriptors for async partial accessor rules (implementation TBD).
samples/Ioc/IocSample/IocSample.csproj Enables AsyncMethodInject feature in sample.
samples/Ioc/IocSample/Generated/*ServiceRegistration.g.cs Updates generated sample output to include Task-based registrations.
samples/Ioc/IocSample/AsyncInject.cs Adds sample async-init service using [IocInject] on Task-returning method.
docs/Ioc/13_MSBuild_Configuration.md Documents AsyncMethodInject flag and default feature set note.
docs/Ioc/10_Wrapper.md Documents Task<T> wrapper semantics and limitations.
docs/Ioc/04_Field_Property_Method_Injection.md Documents async method injection rules, ordering, and diagnostics.
.github/agents/*.agent.md Updates agent tool manifests (adds vscode/resolveMemoryFileUri, tweaks model/tools ordering).

- `GetNonCollectionWrapperKind` should classified `Task` as `WrapperKind.None`
- Container.Basic.spec.md outdated example
- Grammar of `IocContainerGlobalOptions`

Co-authored-by: Copilot <copilot@github.com>
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 105 out of 107 changed files in this pull request and generated 2 comments.

@AndyElessar AndyElessar self-assigned this Apr 2, 2026
- Change SGIOC030 to SGIOC028.
- Add test for SGIOC021.
- Update SGIOC021, SGIOC027, SGIOC029 for better diagnostic coverage.
@AndyElessar AndyElessar requested a review from Copilot April 3, 2026 16:40
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 135 out of 137 changed files in this pull request and generated 6 comments.

…MethodInject feature

Co-authored-by: Copilot <copilot@github.com>
@AndyElessar AndyElessar merged commit aaa44bc into main Apr 3, 2026
5 checks passed
@AndyElessar AndyElessar deleted the feature/async-method-inject branch April 3, 2026 18:10
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.

2 participants