Пример #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
            var container = new Container();
            var provider  = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            container.RegisterSingle <ILocalizedStringProvider>(provider);

            var factory = new UowHandlerFactory(container);

            factory.Register <SchoolContext>(lifestyle: new WebApiRequestLifestyle());
            container.RegisterWebApiRequest <IUowHandlerFactory>(() => factory);

            container.Verify();

            IoC.SetContainerProvider(() => container);
            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
            FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration);
        }
Пример #2
0
        public ScanningRegistry()
        {
            var provider = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            For <ILocalizedStringProvider>().Use(provider);
            For <IUnitOfWork>().Use <UnitOfWork>();
            For <IDataContext>().Use <SchoolContext>();
            AssemblyScanner.FindValidatorsInAssemblyContaining <StudentEditValidator>()
            .ForEach(result => For(result.InterfaceType).Singleton().Use(result.ValidatorType));
        }
Пример #3
0
        public static void Initialize()
        {
            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
            var container = new Container();
            var provider  = LocalizationConfig.RegisterResources(Assembly.GetAssembly(typeof(StudentFriendlyNames)));

            container.RegisterSingle <ILocalizedStringProvider>(provider);

            //container.RegisterPerWebRequest<SchoolContext>();
            //container.RegisterPerWebRequest<IUnitOfWork, UnitOfWork>();

            var factory = new UowHandlerFactory(container);

            //factory.Register("default", () => new UnitOfWork(new SchoolContext()), new WebRequestLifestyle());
            //factory.Register("backup", () => new UnitOfWork(new BackupContext()), new WebRequestLifestyle());
            factory.Register <SchoolContext>(lifestyle: new WebRequestLifestyle());
            //factory.Register<FakeContext>("FakeContext", new WebRequestLifestyle());
            container.RegisterPerWebRequest <IUowHandlerFactory>(() => factory);
            container.Verify();
            IoC.SetContainerProvider(() => container);
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            FluentValidationModelValidatorProvider.Configure();
        }