I am using MVC 4 with Code First and just starting to use the Fluent API, but I can't find anywhere where it is mentioned how to provide validation error messages? Can this only be done by using Data Annotations?
On possibility is to use Data Annotations. Another possibility is to use a differehnt validation framework such as FluentValidation.NET which allows you to specify the error message in your validator rules.
Related
I am building a web application in .NET Core following the Clean Architecture. I have an use case class for creating an user. Each user has a role which is passed in as an id. The use case will call to the User Repository for creating the user.
Currently, I am using FluentValidation for validating the request object. It is just pure checking such as length, not empty, etc..
My problem is that I don't know where to put the validation logic for validating the existence of the provided role. The validator is currently in the Application layer. I am going with putting the validation logic in the User repository but that doesn't sound right to me.
Do you have any ideas?
Thank you in advance.
You should add it in the validator using Fluent Validation. There are options to make custom validator and to make them async with Fluent Validation.
Creating a method in the repository for checking for the role is not necessarily wrong. But it should defently be called in validation layer along with other checks like not empty etc. etc.
For performance sake make sure that you call the check once all the other validations have passed.
I have problems deciding on how the OrmLiteConnectionFactory should be passed to the different classes. Should it be done by injecting the container into the constructors? It is a message based design if that matters.
Basically you'd just want to pass a "reference" to what connection you'd want your Service to be executed with.
ServiceStack's Multitenancy docs shows different approaches of specifying the DB connection to use per Request DTO message, including using a custom filter, or utilizing the built-in [ConnectionInfo] or [NamedConnection] attributes.
Or if you prefer you can resolve which DB connection you want to use with your Services logic by resolving it from a IDbConnectionFactory dependency.
I have already gone through the below link to mask/hide/encrypt sensitive data before logging but unable to do so using Mule4. Can someone please share if implemented or suggestions?
http://bushorn.com/encrypting-a-json-element/
The link is no longer available. I'll assume it is a method base on some log4j2 interception that will not work on Mule 4. What you can do is create a custom logging component with the Mule SDK and apply the same logic there, avoiding trying to intercept Mule 4 logging.
I have a java web application running on Spring Web FLow,Spring Faces. I would like to ask as to how to properly manage error messages display. Should I do the usual storing of error messages on the session? Or is there a better handling by Spring regarding the matter.
The flashScope is intended for just this type of "display a once-off message to the user" usage. You can use it in combination with a resource bundle and the or tags to retrieve the localized error string from a key stored in the flashScope.
Spring Web Flow offers a level of automation for error messages if you make use of the validation framework so you may not even need to do the above manually. However not knowing your exact use case, it's hard to recommend a specific approach.
I'm using JQuery to load controls dynamically in an ASP.NET development environment using JSON and WebServices. Within this solution I have a business logic layer which has a built in validation mechanism (i.e. validating properties and business rules similar to that of CSLA)
When requesting a new control to be loaded dynamically using JQuery and an ASP.NET WebService, I would like to validate the input from the current control against the business logic validation mechanism (i.e. server side validation) and notify the user if there was any problems.
I managed to achieve this, however, when validation fails in the web service I would like to throw a customer exception containing the validation field id's and associated error messages.
In JQuery, I test for this specific ExceptionType and would like to apply the error messages dynamically to the controls listed in the exception type properties. This is where my problem comes in. Even though I created a custom exception with custom properties the exception that is passed to JQuery in JSON format from the WebService is still a standard exception with none of the additional properties listed. I could simply create a JSON formatted string of values in the exception's message property but would ultimately prefer something a little more elegant. Does anyone know how you can override the serialized exception created by ASP.NET for situations such as this...
Thank you in advance...
G
I ran into something very similar a couple days ago - basically there's no way to make ASP.NET generate custom exceptions. This is by design, since returning a specific type of exceptions would
[...] expose implementation
details/bugs to the clients. We could
do something with special exception
type that we let pass through, but its
too late for this release [...]
You could always return different HTTP status codes, and have the browser handle them as custom exceptions - for example, a 500 error would mean one thing, a 401 something else, etc. I think the best solution is to make your method return a string with the exception stack - not elegant, but at least this way the client has all the exception details.
Dave Ward also has info on ASP.NET AJAX service errors.