Skip to content

Fix localplugincontext serviceprovider#10

Merged
mkholt merged 6 commits intomainfrom
fix_localplugincontext_serviceprovider
May 1, 2026
Merged

Fix localplugincontext serviceprovider#10
mkholt merged 6 commits intomainfrom
fix_localplugincontext_serviceprovider

Conversation

@mkholt
Copy link
Copy Markdown
Member

@mkholt mkholt commented Apr 30, 2026

This pull request improves the detection of improper usage of LocalPluginContext in 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 of LocalPluginContext as a service argument, ensuring more robust diagnostics and guidance for users. Additionally, it enhances test coverage and updates the LocalPluginContext implementation to store the service provider reference.

Analyzer improvements

  • The LocalPluginContextAsServiceAnalyzer now detects both explicit (RegisterStep<TEntity, LocalPluginContext>) and implicit (method group with LocalPluginContext parameter) usages, reporting diagnostic XPC3004 in both cases. This is achieved by adding a new code path that inspects method group parameters for LocalPluginContext. [1] [2]

Test enhancements

  • Refactored LocalPluginContextAsServiceAnalyzerTests to 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

  • The XPC3004 rule documentation was expanded with an additional violation example demonstrating the new implicit detection (method group with LocalPluginContext parameter). [1] [2]

LocalPluginContext improvements

  • The LocalPluginContext class now stores a reference to the provided IExtendedServiceProvider, and the corresponding test was updated to assert this behavior. [1] [2]

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 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 LocalPluginContextAsServiceAnalyzer to flag implicit RegisterStep<TEntity> usages where TService is inferred as LocalPluginContext via 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 LocalPluginContext and 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)
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 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 LocalPluginContextAsServiceAnalyzer to detect implicit LocalPluginContext usage via method groups / typed lambdas on single-type-arg RegisterStep<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/assert ServiceProvider.

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.

Comment thread XrmPluginCore.SourceGenerator/rules/XPC3004.md Outdated
@mkholt mkholt merged commit b1ca7fb into main May 1, 2026
1 check passed
@mkholt mkholt deleted the fix_localplugincontext_serviceprovider branch May 1, 2026 04:44
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