public ErrorMessageExamplesController() { // for simplicity this is here, but in a real world you would initialize it at the root of your application (see DependencyInjectionExample) var validation = new AutoValidation(cfg => cfg.AddProfile <UserModel2Profile>()); _factory = validation.CreateFactory(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var validator = new AutoValidation(exp => exp.AddProfiles(typeof(Model1Profile).Assembly)); validator.AssertExpressionsAreValid(); var builder = new ContainerBuilder(); // When you do service population, it will include your controller types automatically. builder.Populate(services); builder.RegisterAssemblyModules(typeof(AutoValidation).Assembly); builder.Register(r => validator.CreateFactory()); var appContainer = builder.Build(); return(new AutofacServiceProvider(appContainer)); }
public HomeController() { // for simplicity this is here, but in a real world you would initialize it at the root of your application (see DependencyInjectionExample) var validation = new AutoValidation(cfg => { cfg.AddProfile <UserModelProfile>(); cfg.Settings.UseCamelCase = true; }); _factory = validation.CreateFactory(); }