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();
        }
Ejemplo n.º 2
0
        // 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));
        }
Ejemplo n.º 3
0
        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();
        }