/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { // Remote Validator taken from // http://nripendra-newa.blogspot.co.uk/2011/05/fluent-validation-remote-validation.html // NinjectValidator is a Ninject Exetension listed on the Ninject Website used for FluentValidation with MVC 4 FluentValidationModelValidationFactory validationFactory = (metadata, context, rule, validator) => new RemoteFluentValidationPropertyValidator(metadata, context, rule, validator); var ninjectValidatorFactory = new NinjectValidatorFactory(kernel); var validationProvider = new FluentValidationModelValidatorProvider(ninjectValidatorFactory); validationProvider.Add(typeof(RemoteValidator), validationFactory); ModelValidatorProviders.Providers.Add(validationProvider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; kernel.Load<FluentValidatorModule>(); // Ninject with EF DbContext // http://stackoverflow.com/questions/11921883/how-to-handle-dbcontext-when-using-ninject // Must ensure the same db context is injected into each service per web request kernel.Bind<IProductService>().To<ProductService>().InRequestScope(); kernel.Bind<IUserService>().To<UserService>().InRequestScope(); kernel.Bind<ICategoryService>().To<CategoryService>().InRequestScope(); kernel.Bind<ICartService>().To<CartService>().InRequestScope(); kernel.Bind<IOrderService>().To<OrderService>().InRequestScope(); kernel.Bind<StoreContext>().ToSelf().InRequestScope(); }
public static void Initialize() { var container = AutofacDependencyResolver.Current.ApplicationContainer as IContainer; var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new ModelValidatorFactory()); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; fluentValidationModelValidatorProvider.AddImplicitRequiredValidator = false; ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); }
/// <summary> /// Initializes the FluentValidationModelValidatorProvider using the default options and adds it in to the ModelValidatorProviders collection. /// </summary> public static void Configure(Action<FluentValidationModelValidatorProvider> configurationExpression = null) { configurationExpression = configurationExpression ?? delegate { }; var provider = new FluentValidationModelValidatorProvider(); configurationExpression(provider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; ModelValidatorProviders.Providers.Add(provider); }
/// <summary> /// Initializes the FluentValidationModelValidatorProvider using the default options and adds it in to the ModelValidatorProviders collection. /// </summary> public static void Configure(Action <FluentValidationModelValidatorProvider> configurationExpression = null) { configurationExpression = configurationExpression ?? delegate { }; var provider = new FluentValidationModelValidatorProvider(); configurationExpression(provider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; ModelValidatorProviders.Providers.Add(provider); }
private static void SetupValidationAndMetadata() { var factory = new NinjectValidatorFactory(); var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(factory) { AddImplicitRequiredValidator = false }; ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; ModelMetadataProviders.Current = new CustomModelMetadataProvider(factory); }
public static IConfigure UsingFluentValidation(this IConfigure configure) { //DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; var factory = configure.Container.Get<CommandValidatorFactory>(); FluentValidationModelValidatorProvider.Configure(p => { p.ValidatorFactory = factory; p.AddImplicitRequiredValidator = false; }); var validatorFactory = configure.Container.Get<DefaultValidatorFactory>(); var validatorProvider = new FluentValidationModelValidatorProvider(validatorFactory); validatorProvider.AddImplicitRequiredValidator = false; ModelValidatorProviders.Providers.Add(validatorProvider); return configure; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); container = new WindsorContainer(); container.Register(new ContainerRegistration()); DataAnnotationsModelValidatorProvider .AddImplicitRequiredAttributeForValueTypes = false; var factory = new WindsorValidatorFactory(container); var fvProvider = new FluentValidationModelValidatorProvider(factory); ModelValidatorProviders .Providers.Add(fvProvider); }
/// <summary> /// Initialize Mvc factories. /// </summary> public static void Initialize(IKernel kernel) { // inject view engine. IViewEngine engine = kernel.Resolve<IViewEngine>(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine); // inject controllers. WindsorControllerFactory controllerFactory = new WindsorControllerFactory(kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); // inject model binders. WindsorModelBinderProvider binderProvider = kernel.Resolve<WindsorModelBinderProvider>(); ModelBinderProviders.BinderProviders.Add(binderProvider); // inject model validators. WindsorValidatorFactory validatorFactory = new WindsorValidatorFactory(kernel); FluentValidationModelValidatorProvider validatorProvider = new FluentValidationModelValidatorProvider(validatorFactory); ModelValidatorProviders.Providers.Add(validatorProvider); // initialize dotless preprocessors. LessPreprocessor dotless = kernel.Resolve<LessPreprocessor>(); Bundle.RegisterStylePreprocessor(dotless); }
public override void OnConfigureValidation() { //DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; var factory = Container.Get<CommandValidatorFactory>(); FluentValidationModelValidatorProvider.Configure(p => { p.ValidatorFactory = factory; p.AddImplicitRequiredValidator = false; }); var validatorFactory = Container.Get<DefaultValidatorFactory>(); var validatorProvider = new FluentValidationModelValidatorProvider(validatorFactory); validatorProvider.AddImplicitRequiredValidator = false; ModelValidatorProviders.Providers.Add(validatorProvider); base.OnConfigureValidation(); }
public void Setup() { this.provider = new FluentValidationModelValidatorProvider(new AttributedValidatorFactory()); ModelValidatorProviders.Providers.Add(this.provider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; var viewData = new ViewDataDictionary<DummyViewModel>(new DummyViewModel()); var mockHttpContext = HttpMocks.GetHttpContextMock(); var controllerContext = new Mock<ControllerContext>(mockHttpContext.Object, new RouteData(), new Mock<ControllerBase>().Object); var mockViewContext = new Mock<ViewContext>( controllerContext.Object, new Mock<IView>().Object, viewData, new TempDataDictionary(), TextWriter.Null); mockViewContext.SetupGet(c => c.ViewData).Returns(viewData); mockViewContext.SetupGet(c => c.HttpContext).Returns(mockHttpContext.Object); var mockViewDataContainer = new Mock<BaseView<DummyViewModel>>(); mockViewDataContainer.Object.SetViewData(viewData); mockViewDataContainer.Setup(v => v.WebElementTranslations).Returns(new WebElementLocalizer(null)); this.htmlHelper = new HtmlHelper<DummyViewModel>(mockViewContext.Object, mockViewDataContainer.Object); }
private static void RegisterValidationAttributes(IKernel kernel) { NinjectValidatorFactory ninjectValidatorFactory = new NinjectValidatorFactory(kernel); var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(ninjectValidatorFactory); fluentValidationModelValidatorProvider.AddImplicitRequiredValidator = false; FluentValidationModelValidatorProvider .Configure(x => x.ValidatorFactory = ninjectValidatorFactory); DataAnnotationsModelValidatorProvider .AddImplicitRequiredAttributeForValueTypes = false; AssemblyScanner.FindValidatorsInAssembly(Assembly.GetExecutingAssembly()) .ForEach(match => kernel.Bind(match.InterfaceType).To(match.ValidatorType)); }
public override void Spin(IRotorContext context) { var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new ServiceLocatorValidatorFactory()) { AddImplicitRequiredValidator = false }; ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); }
public void Setup() { this.contextCulture = Thread.CurrentThread.CurrentCulture; this.contextUiCulture = Thread.CurrentThread.CurrentUICulture; this.provider = new FluentValidationModelValidatorProvider(new AttributedValidatorFactory()); ModelValidatorProviders.Providers.Add(this.provider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; this.htmlHelper = HttpMocks.GetHtmlHelper<DummyViewModel>(new ViewDataDictionary<DummyViewModel>(new DummyViewModel())); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); IContainer container = IoC.Initialize(); DependencyResolver.SetResolver(new StructureMapDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundle(BundleTable.Bundles); FluentValidationModelValidatorProvider.Configure(); FluentValidationModelValidatorProvider validationProvider = new FluentValidationModelValidatorProvider(new StructreMapValidatorFactory(container)); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; validationProvider.AddImplicitRequiredValidator = false; ModelValidatorProviders.Providers.Add(validationProvider); }
protected void Application_Start() { // Initialize engine EngineContext.Initialize(false); // Check if the database is installed bool siteIsInstalled = DataSettingsHelper.SiteIsInstalled; // Resolve dependency var dependencyResolver = new GatherDependencyResolver(); DependencyResolver.SetResolver(dependencyResolver); // Register site areas AreaRegistration.RegisterAllAreas(); // Register filters and routes RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); // Register fluentvalidation var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new ValidatorFactory()); ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; fluentValidationModelValidatorProvider.AddImplicitRequiredValidator = false; // Register script bundles var adminCssBundle = new Bundle("~/areas/admin/content/core.css", new CssMinify()); adminCssBundle.AddDirectory("~/areas/admin/content/", "*.css", true); BundleTable.Bundles.Add(adminCssBundle); var adminJsBundle = new Bundle("~/areas/admin/scripts/core.js", new JsMinify()); adminJsBundle.AddDirectory("~/areas/admin/scripts/jquery/", "*.js", true); BundleTable.Bundles.Add(adminJsBundle); var coreCssBundle = new Bundle("~/content/css/core.css", new CssMinify()); coreCssBundle.AddFile("~/Content/Css/normalize.css"); coreCssBundle.AddFile("~/Content/Css/styles.css"); coreCssBundle.AddFile("~/Content/Css/jquery-ui-1.8.21.css"); coreCssBundle.AddFile("~/Content/Css/leaflet.css"); coreCssBundle.AddFile("~/Content/Css/leaflet.zoomfs.css"); BundleTable.Bundles.Add(coreCssBundle); var jqueryJsBundle = new Bundle("~/content/jquery.js", new NoTransform()); jqueryJsBundle.AddDirectory("~/Scripts/jQuery/", "*.js"); BundleTable.Bundles.Add(jqueryJsBundle); var coreJsBundle = new Bundle("~/content/core.js", new JsMinify()); coreJsBundle.AddDirectory("~/Scripts/", "*.js"); BundleTable.Bundles.Add(coreJsBundle); var mapJsBundle = new Bundle("~/content/coremap.js", new JsMinify()); mapJsBundle.AddFile("~/Scripts/PerPage/core-maps.js"); BundleTable.Bundles.Add(mapJsBundle); var homeJsBundle = new Bundle("~/content/home.js", new JsMinify()); homeJsBundle.AddFile("~/Scripts/PerPage/home.js"); BundleTable.Bundles.Add(homeJsBundle); var projectDetailJsBundle = new Bundle("~/content/projectdetail.js", new JsMinify()); projectDetailJsBundle.AddFile("~/Scripts/PerPage/project-detail.js"); BundleTable.Bundles.Add(projectDetailJsBundle); var projectListingJsBundle = new Bundle("~/content/projectlisting.js", new JsMinify()); projectListingJsBundle.AddFile("~/Scripts/PerPage/project-listing.js"); BundleTable.Bundles.Add(projectListingJsBundle); if (siteIsInstalled) { // Kick off the scheduled tasks TaskManager.Instance.Initialize(); TaskManager.Instance.Start(); } }
protected virtual void RegisterValidationProvider() { DataAnnotationsModelValidatorProvider .AddImplicitRequiredAttributeForValueTypes = false; var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new ValidatorFactory()) { AddImplicitRequiredValidator = false }; ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); }
private void RegisterIoC() { var builder = new ContainerBuilder(); builder.Register(c => new CustomModelMetadataProvider(c.Resolve<IComponentContext>())) .As<DataAnnotationsModelMetadataProvider>() .InstancePerLifetimeScope(); builder.RegisterModule(new DatabaseModule()); builder.RegisterModule(new EmailModule()); builder.RegisterModule(new DenormalizerModule()); builder.RegisterModule(new EventModule()); builder.RegisterModule(new DomainModule()); builder.RegisterModule(new HubsModule()); builder.RegisterModule(new WebModule()); builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); builder.RegisterType<ExtensibleActionInvoker>().As<IActionInvoker>(); builder.RegisterControllers(Assembly.GetExecutingAssembly()).InjectActionInvoker(); builder.RegisterFilterProvider(); builder.RegisterType<ServiceLocatorValidatorFactory>().As<IValidatorFactory>(); var findValidatorsInAssembly = AssemblyScanner.FindValidatorsInAssembly(Assembly.GetExecutingAssembly()); foreach (var item in findValidatorsInAssembly) builder.RegisterType(item.ValidatorType).PropertiesAutowired(); Container = builder.Build(); var fluentValidationModelValidatorProvider = new FluentValidationModelValidatorProvider(new ServiceLocatorValidatorFactory(Container)) { AddImplicitRequiredValidator = false }; ModelValidatorProviders.Providers.Add(fluentValidationModelValidatorProvider); ModelMetadataProviders.Current = Container.Resolve<DataAnnotationsModelMetadataProvider>(); DependencyResolver.SetResolver(new AutofacDependencyResolver(Container)); }