CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

Please exclude fluent validators registration by default #340

Closed VladislavBI closed 1 month ago

VladislavBI commented 2 months ago

In my code I have some Abstract validators, For some of them use my inject db context. Because this context is scoped and carter register validators as a singleton I receive an exception. I have found a solution , but can you please exclude this behavior by default, because it is not obvious

builder.Services.AddCarter(configurator: config =>
{
    config.WithEmptyValidators();
});
jchannon commented 1 month ago

IMHO you shouldn't be using Validators for business validation, that should be separate and the validator should be for empty fields etc.

Apologies the WithEmptyValidators is not obvious but that's what it's there for so your solution is the correct one.