What is the IShouldNormalize's alternative in Abp.io? - aspnetboilerplate

I have a project, that created in Abp.io framework. I before used ASP.NET Boilerplate framework and ASP.NET Boilerplate has IShouldNormalize interface for normalize request's input. But I don't find IShouldNormalize's alternative in Abp.io
What is the IShouldNormalize's alternative in Abp.io ?

No alternative. You can use IValidatableObject for validation and
simple normalization. You can add your own method and call in the
application service.
But we suggest you to make it in your application service method
explicitly
https://github.com/abpframework/abp/issues/1908
You can use the IValidatableObject for validation and normalization for your needs.
IValidatableObject has just a method named Validate you can define your normalization rules in here, that you normally do in the Normalize method of theIShouldNormalize interface.

Related

How to implement custom validation in Blazor

How I can implement validation to my model, but not use attributes in this class, because, this class has some behavior of dependency on how to fill properties.
For example, if property IsDropDown is true, I must validate only DropDownValue else I must validate other properties.
Use FluentValidation
Read Steve Sanderson's Blog : Integrating FluentValidation with Blazor
And Chris Sainty's article : Using FluentValidation for Forms Validation in Blazor

Does ASP.NET web API support IValidatableObject?

I have a view model that implements IValidatableObject and also has several validation attributes. When I attempt to call an action on my ApiController, only the attribute validation is performed. Does ASP.NET Web API not support IValidatableObject? What's the alternative for complex validation that cannot be represented by a single attribute?
Edit: Somewhere along the line, I must have fudged something up. The validation mysteriously started working as expected. Looks like IValidatableObject is definitely supported by default.
With Web API 2.1 (Microsoft.AspNet.WebApi nuget 5.1.x), I experienced IValidatableObject's Validate method not being called if any of the validation attributes are invalid. Hence, all validation attributes that have been applied to your class's properties must first pass as valid before that class's Validate method will be called.
If, for example, you have a property with the RequiredAttribute and you do not put a value in that field, your implementation of IValidatableObject's Validate method will not be called. Although not technically a bug, I expected the Validate method to be called every time I validate.
Not yet tried IValidatableObject on webapi, but it should be supported according to the documentation the Validation provider for DataAnnotations (DataAnnotationsModelValidatorProvider) provide also IValidatableObject validation. See here: http://msdn.microsoft.com/en-us/library/system.web.http.validation.providers(v=vs.108)
Anyway, you can use also Object level ValidationAttribute that you can use to decorated a class...It is not so easy as IValidatableObject, but should work.
As of now, IValidatableObject is supported.

How to stop Ninject from overriding custom DataAnnotationsModelValidatorProvider?

I have a custom DataAnnotationsModelValidatorProvider for doing model validation in a more dynamic way then just adding attributes. I tried to add my provide to the global.asax.cs like so:
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new AttributeValidatorProvider());
But once I load my form, I get an error saying "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required".
According to a comment on this blog, this is because Ninject is overriding custom validator providers.
I'm fairly new to MVC and I can't seem to find a way to tell Ninject to accept my custom providers as well, how would I go about fixing this problem?
For the record: I do not wish to use Fluentvalidation.net, I want to stick with the default MVC validations (for the most part).
There is another way (works in MVC 4 for sure):
Find your class which inherit IdependencyResolver interface and add to constructor _kernel.Unbind<ModelValidatorProvider>(); - you just unbind ninject validator and there should be no colission with default validator.
In my case my constructor looks like this:
public NinjectDependencyResolver()
{
_kernel = new StandardKernel();
_kernel.Unbind<ModelValidatorProvider>();
AddBindings();
}
Change the registration of the provider to
Rebind<ModelValidatorProvider>().To<AttributeValidatorProvider>();

Difference between use of a controller factory and NinjectHttpApplication?

Using Ninject 2 MVC 3. Correct me if i am wrong but ive seen two way of using Ninject in an MVC 3 application. We can use a new controller factory which is like ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); or using NinjectHttpApplication and then configure the kernel.
I was wondering what difference between use of a controller factory and NinjectHttpApplication to configure the binding for DI?
And what are the best place to setup DI ?
NinjectHttpApplication calls ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()) internally.
But additionally it sets up various bindings and provides many new features. In other words it's less work and adds new features. Best you read my blog post about the MVC3 extension. http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/

Validation framework for business app built on Spring 2.5

What could the best strategy for writing validation layer for mid-enterprise level business application built on Spring 2.5
I know that Spring provides facility where we can implement Validator interface and write validation logic in validate method. But this will be restricted to only web requests coming through spring controller.
I would like to develop the validation framework which can be utilized during web-services calls.
In other words, the framework can remain and be called independently without the need of implementing Validator interface and then too it can be automatically integrated into Spring MVC flow.
Hope you get my point.
The Spring Validation framework can be used outside of Spring MVC. What WebServices Stack are you using? If you are using Spring-WS (Spring's Web Services stack) they have special instructions on how to set up the validator here:
http://static.springframework.org/spring-ws/sites/1.5/reference/html/server.html#d0e2313
If you are using some other stack, it is probably easier to implement something for that stack (or find one) that will use Spring's validation framework.
Recall that the Validator interface defines two methods:
boolean supports(Class clazz)
void validate(Object target, Errors errors)
The Object target is your form object, which is the whole object representing the page to be shown to the user. The Errors instance will contain the errors that will be displayed to the user.
So, what you need to do is define an intermediary that can be called with the specifics in your form that you want to validate which are also the same as in your web service. The intermediary can take one of two forms:
(probably the best):
public interface ErrorReturning {
public void getErrors(Errors errors);
}
(this can get ugly really fast if more than two states are added):
public interface ValidationObject {
public Errors getErrors(Errors errors);
public Object getResultOfWebServiceValidation();
}
I would suggest that the first approach be implemented. With your common validation, pass an object that can be used for web service validation directly, but allow it to implement the getErrors() method. This way, in your validator for Spring, inside your validation method you can simply call:
getCommonValidator().validate(partialObject).getErrors(errors);
Your web service would be based around calls to getCommonValidator().validate(partialObject) for a direct object to be used in the web service.
The second approach is like this, though the interface only allows for an object to be returned from the given object for a web service validation object, instead of the object being a usable web service validation object in and of itself.

Resources