Merged
Conversation
…T>`, and use `[IocInject]` on async method
…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>
…asue infinte recursion
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
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
AsyncMethodInjectand model/generator support for async-init services viaTask<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). |
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Models/TransformExtensions.cs
Outdated
Show resolved
Hide resolved
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Generator/Spec/Container.Basic.spec.md
Outdated
Show resolved
Hide resolved
…rectly ban `Task` from nested wrapper
- Change SGIOC030 to SGIOC028. - Add test for SGIOC021. - Update SGIOC021, SGIOC027, SGIOC029 for better diagnostic coverage.
src/Ioc/src/SourceGen.Ioc.SourceGenerator/Analyzer/RegisterAnalyzer.AttributeUsage.cs
Outdated
Show resolved
Hide resolved
…MethodInject feature Co-authored-by: Copilot <copilot@github.com>
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
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
Checklist
Testing
All existing tests and new test are pass.