Conversation
- Introduced `AutoInjectExtensionsAttribute` to generate extension methods for service registration. - Added diagnostics: `LAI006` (multiple extensions), `LAI007` (static partial class), and `LAI104` (unnecessary config). - Enhanced generator to prioritize `AutoInjectExtensionsAttribute` over `AutoInjectConfigAttribute`. - Improved analyzer to validate method names and detect multiple or invalid extensions. - Refactored helper logic into `CompilationExtensions` and added `CSharpIdentifierHelper`. - Updated tests to cover new diagnostics and generator behavior. - Updated resources and documentation for new diagnostics. - Adjusted project configuration to include generator output. - Removed deprecated `AttributeConflictAnalyzer` and unused code.
|
@copilot There are some naming issues that I need your help with, including the following:
If there are better or more suitable names to choose from, please modify them. |
There was a problem hiding this comment.
Pull request overview
This work-in-progress PR adds support for the AutoInjectExtensionsAttribute, which allows users to customize the generated service registration extension methods by decorating a static partial class. This provides more flexibility than the assembly-level AutoInjectConfigAttribute approach.
Key Changes:
- Introduces
AutoInjectExtensionsAttributefor class-level customization of generated extension methods - Adds partial method support (
AddAdditionalServices) to allow custom service registrations - Refactors compilation helper methods from static class to extension methods
- Updates analyzers to validate the new attribute usage patterns
Reviewed changes
Copilot reviewed 19 out of 22 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Ling.AutoInject.SourceGenerators/Extensions/CompilationExtensions.cs | New file with compilation extension methods (contains critical syntax error) |
| src/Ling.AutoInject.SourceGenerators/Helpers/CSharpIdentifierHelper.cs | New validation helper for C# identifiers |
| src/Ling.AutoInject.SourceGenerators/Helpers/CompilationHelpers.cs | Deleted - replaced by CompilationExtensions |
| src/Ling.AutoInject.SourceGenerators/SourceCodes.cs | Adds AutoInjectExtensionsAttribute definition and removes redundant constructor from AutoInjectConfigAttribute |
| src/Ling.AutoInject.SourceGenerators/AutoInjectGenerator.cs | Updated to support AutoInjectExtensionsAttribute, generate partial methods, and include optional IConfiguration parameter |
| src/Ling.AutoInject.SourceGenerators/Analyzers/ExtensionMethodAnalyzer.cs | New analyzer for validating AutoInjectExtensionsAttribute usage |
| src/Ling.AutoInject.SourceGenerators/Analyzers/InvalidAutoInjectConfigAnalyzer.cs | Updated to use new helper methods and detect unnecessary AutoInjectConfig usage |
| src/Ling.AutoInject.SourceGenerators/Analyzers/AutoInjectAttributeAnalyzer.cs | New file consolidating attribute validation logic |
| src/Ling.AutoInject.SourceGenerators/Analyzers/NotSupportedFeatureAnalyzer.cs | Updated import from CompilationHelpers to CompilationExtensions |
| src/Ling.AutoInject.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs | Adds new diagnostic rules for extensions validation and unnecessary config usage |
| src/Ling.AutoInject.SourceGenerators/Resources/SR.resx | Adds localized strings for new diagnostics |
| src/Ling.AutoInject.SourceGenerators/Resources/SR.zh-CN.resx | Adds Chinese localized strings for new diagnostics |
| src/Ling.AutoInject.SourceGenerators/Resources/SR.Designer.cs | Auto-generated designer file for resources |
| src/Ling.AutoInject.SourceGenerators/Constants.cs | Adds AutoInjectExtensionsAttributeFullName constant |
| src/Ling.AutoInject.SourceGenerators/AutoInjectSymbols.cs | Adds AutoInjectExtensionsAttributeSymbol property |
| src/Ling.AutoInject.SourceGenerators/AnalyzerReleases.Shipped.md | Documents new diagnostic IDs for the release |
| src/Ling.AutoInject/Ling.AutoInject.csproj | Changes IncludeBuildOutput from false to true |
| src/Directory.Build.props | Removes trailing whitespace |
| tests/Ling.AutoInject.SourceGenerators.Tests/Verifiers/CSharpAnalyzerVerifier.cs | Adds AutoInjectExtensionsAttribute to test sources |
| tests/Ling.AutoInject.SourceGenerators.Tests/AutoInjectGeneratorTests.cs | Adds tests for AutoInjectExtensionsAttribute and partial class scenarios |
| tests/Ling.AutoInject.SourceGenerators.Tests/Analyzers/InvalidAutoInjectConfigAnalyzerTests.cs | Updates tests to use new diagnostic descriptors |
| tests/Ling.AutoInject.SourceGenerators.Tests/Analyzers/ExtensionMethodAnalyzerTests.cs | New test file for ExtensionMethodAnalyzer |
Files not reviewed (1)
- src/Ling.AutoInject.SourceGenerators/Resources/SR.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
* Initial plan * Rename DiagnosticAnalyzer types and tests for better naming consistency Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> * Unify test method naming styles across all test files Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
…sionsAttributeAnalyzer.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
) * Initial plan * Refactor IsValidNamespace to use LINQ All() instead of foreach loop Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
* Initial plan * Add length check in IsValidIdentifierAllowAt for "@" edge case Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
…ach loop (#14) * Initial plan * Use explicit .Where() filter instead of implicit if statement in foreach loop Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> * Use FirstOrDefault instead of Where with foreach loop Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
…16) * Initial plan * Refactor foreach loop to use explicit .Where() filter for AutoInjectConfigAttribute Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
…Symbol (#17) * Initial plan * Refactor foreach loop to use .Select() for mapping classDecl to classSymbol Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
Simplified the comment in `AutoInjectConfigAttributeAnalyzer.cs` to make it more concise. Removed the phrase "or contain invalid characters" from the description of invalid C# identifiers.
|
@copilot |
… features (#18) * Initial plan * docs: Add documentation for Replace and AutoInjectExtensionsAttribute features Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> * docs: Refactor README.md to reference package README for usage documentation Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> * Clarify usage instructions in README Updated usage instructions for clarity. * Clarify usage instructions in README Updated usage instructions for clarity. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> Co-authored-by: Jing Ling <lingjing0921@live.com>
|
@copilot I found that |
Updated the <VersionSuffix> property in Directory.Build.props from `beta-20251119095118` to `beta-20251201143733`.
…tions (#19) * Initial plan * Add replace service and AutoInjectExtensionsAttribute to Features sections in README files Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> * Improve wording for service replacement and AutoInjectExtensionsAttribute descriptions Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ling921 <88094578+ling921@users.noreply.github.com>
|
@copilot this PR is ready to merge, please remove |
This pull request introduces new analyzers and diagnostics to improve validation and customization of dependency injection (DI) code generation. It adds support for class-level customization via
AutoInjectExtensionsAttribute, enhances error reporting for misconfiguration, and refines the documentation to point to more detailed usage instructions. The changes are grouped below by theme.Analyzer and Diagnostic Improvements
AutoInjectConfigAttributeAnalyzerto validate assembly-levelAutoInjectConfigvalues, reporting errors for invalid naming and unnecessary configuration when class-level customization is present.AutoInjectExtensionsAttributeAnalyzerto enforce correct usage ofAutoInjectExtensionsAttribute, including checks for valid method names, single usage per assembly, and requiring the target class to bestatic partial.AnalyzerReleases.Shipped.mdto reflect new rules for replace registration, multiple extension declarations, static partial class requirements, and redundant configuration. [1] [2]Feature and API Enhancements
Replace = true) and class-level customization viaAutoInjectExtensionsAttribute, including optionalIConfigurationparameter support, as documented inREADME.md.AutoInjectExtensionsAttributesource.Refactoring and Documentation
InvalidAutoInjectConfigAnalyzerand replaced its functionality with more targeted analyzers.README.mdto reference the package-level documentation for detailed usage, streamlining the top-level instructions.Other Minor Changes
ConflictingExtensionAnalyzertoMethodNameConflictAnalyzerfor clarity.Directory.Build.propsfor new release.These changes collectively improve the flexibility and correctness of DI code generation, making it easier to customize registration methods and catch configuration errors early.