public override void Load()
        {
            NinjectValidatorFactory ninjectValidatorFactory = new NinjectValidatorFactory(Kernel);

            FluentValidationModelValidatorProvider.Configure(x => x.ValidatorFactory        = ninjectValidatorFactory);
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            AssemblyScanner.FindValidatorsInAssembly(Assembly.GetExecutingAssembly())
            .ForEach(match => Kernel.Bind(match.InterfaceType)
                     .To(match.ValidatorType));

            Kernel.Bind <VeiculoValidation>().To <VeiculoValidation>();
            Kernel.Bind <CombustivelValidation>().To <CombustivelValidation>();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = DependencyContainer.Current ?? new StandardKernel();

            kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

            var ninjectValidatorFactory = new NinjectValidatorFactory(kernel);

            ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(ninjectValidatorFactory));
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

            RegisterServices(kernel);
            return(kernel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);

                var ninjectValidatorFactory = new NinjectValidatorFactory(kernel);
                FluentValidationModelValidatorProvider.Configure(x => x.ValidatorFactory        = ninjectValidatorFactory);
                DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }