Skip to content

Add UseFluentValidationProblemDetail Api#2186

Merged
jeremydmiller merged 8 commits intoJasperFx:mainfrom
XL1TTE:issue-2182-resolve
Feb 16, 2026
Merged

Add UseFluentValidationProblemDetail Api#2186
jeremydmiller merged 8 commits intoJasperFx:mainfrom
XL1TTE:issue-2182-resolve

Conversation

@XL1TTE
Copy link
Contributor

@XL1TTE XL1TTE commented Feb 15, 2026

I liked the idea of auto-registration for problem-detail-specific services within the extension, so I tried to avoid the necessity for additional calls. I agree that the idea of method overload is actually not good and can be confusing, so it's probably a good idea to introduce an additional API for manual configuration.

There is a problem that registration could happen in another place, which is true. The FluentValidationExtension would register services if ExtensionDiscovery is in Automatic mode, which occurs before the configure call. Therefore, it's a good idea to use TryAddSingleton inside UseFluentValidationProblemDetail.

I think using TryAddSingleton inside FluentValidationExtension instead of AddSingleton is also a good practice in this case.

PR may solve issue #2182

I liked the idea of auto-registration for problem-detail-specific services within the extension,
so I tried to avoid the necessity for additional calls. I agree that the idea of method overload is actually not good and can be confusing,
so it's probably a good idea to introduce an additional API for manual configuration.

There is a problem that registration could happen in another place, which is true.
The FluentValidationExtension would register services if ExtensionDiscovery is in Automatic mode, which occurs before the configure call.
Therefore, it's a good idea to use TryAddSingleton inside UseFluentValidationProblemDetail.

I think using TryAddSingleton inside FluentValidationExtension instead of AddSingleton is also a good practice in this case.
@XL1TTE XL1TTE marked this pull request as draft February 15, 2026 13:50
Implemented some tests to check `IFailureAction<>` and `IProblemDetailSource<>` registration behaviour.

Conclusion: UseFluentValidation method register `IFailureAction<>` service after FluentValidationExtensions do.
Therefore two instances of service was added in IServiceCollection.
Changed AddSingleton call to TryAddSingleton inside UseFluentValidation to fix this.
UseFluentValidationProblemDetailExtension -> WolverineOptionsExtensions
@XL1TTE XL1TTE marked this pull request as ready for review February 15, 2026 14:35
@dmytro-pryvedeniuk
Copy link
Contributor

Let me add one more test to your PR

XL1TTE and others added 2 commits February 16, 2026 07:24
In my case, all tests inside Bug_2182_unresolved_IProblemDetailSource failed until I specified opts.Discovery.IncludeAssembly(typeof(Bug_2182_Endpoint.Request).Assembly) in every test case.

I used the following code:
````
_builder.Services.AddWolverine(ExtensionDiscovery.ManualOnly, opts =>
{
    opts.Discovery.IncludeAssembly(typeof(Bug_2182_Endpoint).Assembly); // <- this is the fix!
    opts.UseFluentValidation(); // from Wolverine.FluentValidation
    opts.UseFluentValidationProblemDetail(); // from Wolverine.Http.FluentValidation
});
````
Six out of seven tests passed after that, but one still failed due to how AlbaHost manages exceptions.

All seven tests succeeded after all changes.
@dmytro-pryvedeniuk
Copy link
Contributor

@XL1TTE, Thank you for fixing - my apologies. Need to find why it worked on my side.
Should we maybe rebase upstream now? There are red tests in main, but we have more here.

@jeremydmiller
Copy link
Member

@dmytro-pryvedeniuk @XL1TTE I think this is fine as is, and I'm taking it in right now and adding a note to the docs about this. Not sure how I want to handle this going forward in Wolverine 6. I might vote to pull the FluentValidation pieces into Wolverine.Http so you could stream line the service registration into AddWolverineHttp(), but that's months away.

@jeremydmiller jeremydmiller merged commit 21dfdd4 into JasperFx:main Feb 16, 2026
5 of 9 checks passed
jeremydmiller added a commit that referenced this pull request Feb 16, 2026
…TP middleware

When using ExtensionDiscovery.ManualOnly, users must explicitly call
opts.UseFluentValidationProblemDetail() to register IProblemDetailSource<T>.
References #2182 and PR #2186.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants