-
-
Notifications
You must be signed in to change notification settings - Fork 10
Custom view model validators
Alexanderius edited this page Dec 22, 2019
·
4 revisions
The model validators are working the same as binders.
To use custom model validator you should register it using HttpModelHandler.RegisterModelValidator, it will be added to validators pipeline.
public class Startup
{
public void Configuration(IAppBuilder app)
{
...
HttpModelHandler.RegisterModelValidator<MyModelValidator>();
app.UseSimplifyWeb();
}
public void ConfigureServices(IServiceCollection services)
{
...
DIContainer.Current.Register<MyModelValidator>(LifetimeType.Singleton);
...
}
}Validator should be deriver from IModelValidator interface.
public class MyModelValidator : IModelValidator
{
public void Validate<T>(T model)
{
// Validation logic
}
}If you just want to use your validator without default validators, then you should clear validators list first.
public class Startup
{
public void Configuration(IAppBuilder app)
{
...
HttpModelHandler.ModelValidatorsTypes.Clear();
HttpModelHandler.RegisterModelValidator<MyModelValidator>();
app.UseSimplifyWeb();
}
}- Getting Started
- Main Simplify.Web principles
- Simplify.Web controllers
- Simplify.Web views
- Simplify.Web templates
- Simplify.Web configuration
- Templates variables
- Static content
- Template factory
- Data collector
- String table
- File reader
- Web context
- Environment
- Dynamic environment
- Language manager
- Redirector
- HTML