Add UseFluentValidationProblemDetail Api#2186
Merged
jeremydmiller merged 8 commits intoJasperFx:mainfrom Feb 16, 2026
Merged
Conversation
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.
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.
src/Http/Wolverine.Http.FluentValidation/FluentValidationProblemDetailExtension.cs
Outdated
Show resolved
Hide resolved
src/Http/Wolverine.Http.FluentValidation/FluentValidationExtension.cs
Outdated
Show resolved
Hide resolved
UseFluentValidationProblemDetailExtension -> WolverineOptionsExtensions
Contributor
|
Let me add one more test to your PR |
Add more tests
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.
Contributor
|
@XL1TTE, Thank you for fixing - my apologies. Need to find why it worked on my side. |
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. |
This was referenced Feb 16, 2026
This was referenced Feb 17, 2026
This was referenced Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
FluentValidationExtensionwould register services ifExtensionDiscoveryis in Automatic mode, which occurs before the configure call. Therefore, it's a good idea to useTryAddSingletoninsideUseFluentValidationProblemDetail.I think using
TryAddSingletoninsideFluentValidationExtensioninstead ofAddSingletonis also a good practice in this case.PR may solve issue #2182