Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens the source-generator analyzer rule XPC3004 by expanding detection of improper LocalPluginContext usage in RegisterStep registrations, and aligns tests/docs with the updated behavior. It also updates LocalPluginContext to retain the provided service provider reference.
Changes:
- Extend
LocalPluginContextAsServiceAnalyzerto flag implicitRegisterStep<TEntity>usages whereTServiceis inferred asLocalPluginContextvia a method group. - Refactor analyzer tests to cover explicit/implicit cases via parameterized
[Theory]inputs. - Update XPC3004 documentation with an additional implicit-usage violation example; store the service provider reference in
LocalPluginContextand assert it in tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| XrmPluginCore/LocalPluginContext.cs | Store the passed IExtendedServiceProvider in ServiceProvider. |
| XrmPluginCore.Tests/LocalPluginContextTests.cs | Add assertion that ServiceProvider is preserved. |
| XrmPluginCore.SourceGenerator/rules/XPC3004.md | Document implicit (method-group) violation scenario for XPC3004. |
| XrmPluginCore.SourceGenerator/Analyzers/LocalPluginContextAsServiceAnalyzer.cs | Add implicit detection path for RegisterStep<TEntity> calls with inferred LocalPluginContext. |
| XrmPluginCore.SourceGenerator.Tests/DiagnosticTests/LocalPluginContextAsServiceAnalyzerTests.cs | Parameterize tests to cover both explicit and implicit patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [Theory] | ||
| [InlineData("RegisterStep<Contact, LocalPluginContext>")] | ||
| [InlineData("RegisterStep<Contact>")] | ||
| public async Task Should_Report_XPC3004_When_LocalPluginContext_Explicitly_Specified(string registerStep) |
There was a problem hiding this comment.
Pull request overview
This PR enhances the source-generator analyzer rule XPC3004 to catch additional misuses of LocalPluginContext in RegisterStep registrations, updates tests to cover the new detection paths, and adjusts LocalPluginContext to retain the provided service provider reference.
Changes:
- Extend
LocalPluginContextAsServiceAnalyzerto detect implicitLocalPluginContextusage via method groups / typed lambdas on single-type-argRegisterStep<TEntity>(...). - Refactor analyzer tests to
[Theory]+[InlineData]to cover explicit and implicit cases, including code-fix behavior. - Update XPC3004 documentation with an additional “implicit” violation example; update
LocalPluginContext+ tests to store/assertServiceProvider.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
XrmPluginCore/LocalPluginContext.cs |
Store the passed IExtendedServiceProvider in ServiceProvider. |
XrmPluginCore.Tests/LocalPluginContextTests.cs |
Assert ServiceProvider is stored on construction. |
XrmPluginCore.SourceGenerator/rules/XPC3004.md |
Add an implicit-usage violation example and explanation. |
XrmPluginCore.SourceGenerator/Analyzers/LocalPluginContextAsServiceAnalyzer.cs |
Add implicit detection logic for method groups / typed lambdas. |
XrmPluginCore.SourceGenerator.Tests/DiagnosticTests/LocalPluginContextAsServiceAnalyzerTests.cs |
Parameterize tests to cover explicit/implicit analyzer + code-fix paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request improves the detection of improper usage of
LocalPluginContextin the source generator analyzer and updates related tests and documentation. The main focus is on expanding the analyzer to catch both explicit and implicit usages ofLocalPluginContextas a service argument, ensuring more robust diagnostics and guidance for users. Additionally, it enhances test coverage and updates theLocalPluginContextimplementation to store the service provider reference.Analyzer improvements
LocalPluginContextAsServiceAnalyzernow detects both explicit (RegisterStep<TEntity, LocalPluginContext>) and implicit (method group withLocalPluginContextparameter) usages, reporting diagnosticXPC3004in both cases. This is achieved by adding a new code path that inspects method group parameters forLocalPluginContext. [1] [2]Test enhancements
LocalPluginContextAsServiceAnalyzerTeststo use[Theory]with[InlineData], allowing both explicit and implicit cases to be tested with parameterized input. Test assertions were updated to match the new analyzer logic. [1] [2] [3] [4] [5]Documentation updates
LocalPluginContextparameter). [1] [2]LocalPluginContext improvements
LocalPluginContextclass now stores a reference to the providedIExtendedServiceProvider, and the corresponding test was updated to assert this behavior. [1] [2]