Skip to content

Simplify CheckLicense to use GetRequiredService instead of fallback constructors#1158

Merged
jbogard merged 2 commits into1153-no-constructor-for-type-mediatrlicensinglicenseaccessor-can-be-instantiated-using-services-from-the-service-container-and-default-valuesfrom
copilot/sub-pr-1157
Feb 22, 2026
Merged

Simplify CheckLicense to use GetRequiredService instead of fallback constructors#1158
jbogard merged 2 commits into1153-no-constructor-for-type-mediatrlicensinglicenseaccessor-can-be-instantiated-using-services-from-the-service-container-and-default-valuesfrom
copilot/sub-pr-1157

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

CheckLicense was using GetService with ?? new LicenseAccessor(...) / ?? new LicenseValidator(...) fallbacks, duplicating construction logic already handled by ServiceRegistrar.AddRequiredServices.

Changes

  • MediatRServiceCollectionExtensions.cs: Replace GetService + fallback pattern with direct GetRequiredService<LicenseAccessor>() and GetRequiredService<LicenseValidator>().
// Before
var licenseAccessor = serviceProvider.GetService<LicenseAccessor>() ?? new LicenseAccessor(
    serviceProvider.GetRequiredService<MediatRServiceConfiguration>(),
    serviceProvider.GetRequiredService<ILoggerFactory>()
);
var licenseValidator = serviceProvider.GetService<LicenseValidator>()
                       ?? new LicenseValidator(serviceProvider.GetRequiredService<ILoggerFactory>());

// After
var licenseAccessor = serviceProvider.GetRequiredService<LicenseAccessor>();
var licenseValidator = serviceProvider.GetRequiredService<LicenseValidator>();
  • ServiceFactoryTests.cs: Updated the manual registration test to explicitly register LicenseAccessor and LicenseValidator, which are now required in the container.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ogic

Co-authored-by: jbogard <104498+jbogard@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to address feedback from PR #1157 Simplify CheckLicense to use GetRequiredService instead of fallback constructors Feb 22, 2026
Copilot AI requested a review from jbogard February 22, 2026 19:22
@jbogard jbogard marked this pull request as ready for review February 22, 2026 19:26
@jbogard jbogard merged commit 25ffe81 into 1153-no-constructor-for-type-mediatrlicensinglicenseaccessor-can-be-instantiated-using-services-from-the-service-container-and-default-values Feb 22, 2026
2 checks passed
@jbogard jbogard deleted the copilot/sub-pr-1157 branch February 22, 2026 19:28
This was referenced Mar 8, 2026
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