Comments (6)
@damianh All your points makes sense and totally agree that fluent validator objects are quite expensive to instantiate. Besides it is best to have clear separation of concerns as you rightly pointed out.
I would strongly advise that message validators, your first line of defense after auth, work exclusively with the message and not have any dependencies on services. (There are always exceptions OC)
This is a good rule of thumb!
Also @JoeStead indicated in earlier comment around the impact on performance.
I am closing this.
from carter.
The ability to change the lifecycle of the registration using the DI container, in my opinion, is crucial; otherwise, it would render the use of Carter.NET in applications that are being migrated to minimal APIs unfeasible. It is quite common to have validators coupled with some sort of database access. For example, when checking the uniqueness of an email address or some other value. I understand that FluentValidation objects are quite expensive to instantiate, but in my case, and I believe in the case of others, it's a price we are willing to pay.
The automatic registration of all validators in an application as Singletons becomes a deal-breaker, even affecting previous code, as it prevents the application from starting due to errors generated during the build of the DI container. One possibility would be to disable the automatic registration of validators, along with the ability to validate the request directly at the endpoint, and leave it to the developer to manually execute the validation procedure.
from carter.
It's probably best to make this configurable, in the cases where you can have validators as a singleton, that would be preferable because it will have an impact on performance. There have been other discussions around the use of the container / how things are registered, and I imagine those discussions will continue for a while :)
from carter.
@JoeStead understand your comments around requiring it to be configurable. Let me get my head around it and see if I can make it configurable. Apparently I did send a PR to change it to scoped, I think it can be ignored.
from carter.
@mysticmind Looks like you are doing a bit of CQRS there. You have a race condition in your validator and your domain logic is leaking - two concurrent requests with the same name
will succeed the FindByNameAsync()
but then you'll get duplicate / exception in next layer (domain or db). Leave the set based concerns at domain / db level where you can have strong consistency guarantees.
I would strongly advise that message validators, your first line of defense after auth, work exclusively with the message and not have any dependencies on services. (There are always exceptions OC).
My understanding is that fluent validator objects are quite expensive to instantiate due to compiled expressions etc as such should be singleton wrt to the life time of your app (I actually use static instances). I might be out of date with this understanding, but if I'm correct, the only time you might need instances if there is a some sort setting adjustable at runtime.
from carter.
from carter.
Related Issues (20)
- `WithGroupName` and `WithDescription` results in that module not being surface in SwaggerUI HOT 6
- [Question] Is it possible to do property injection on a CarterModulse version 7 and autofac HOT 1
- Conditionaly Load UnLoad Module HOT 1
- How to configure my filters HOT 1
- [QUESTION] Any sample code using .WithOpenApi HOT 1
- Add support for registering an endpoint filter using an endpoint filter factory HOT 2
- [Question] The future of Carter HOT 1
- Endpoints Not Visible in EndpointsApiExplorer HOT 4
- suggest for nested work HOT 1
- Error On Register IN DI HOT 5
- Removed support to apply endpoint conventions globally HOT 2
- Can't find testhost.deps.json HOT 1
- Unable to change the field of the response data body to uppercase HOT 2
- Minimal AP Versioning HOT 2
- Open Api Summary is not drawing on Swagger UI HOT 3
- Trying to get swagger working with my project. HOT 4
- carter is missing NuGet package README file HOT 1
- Make BindFile and BindFiles extension methods public HOT 1
- Consider making ICarterModule.AddRoutes a static abstract method HOT 8
- Is it possible to apply a global filter with Carter that applies to all endpoints of all Carter modules? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carter.