Exemple #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            container = new WindsorContainer();
            container.Register(
                Classes.FromAssemblyContaining <WebAssemblyIdentity>()
                .BasedOn <Controller>()
                .LifestyleTransient(),
                Classes.FromAssemblyContaining <WebAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Classes.FromAssemblyContaining <MvcPagesAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Classes.FromAssemblyContaining <VisualAssertionsAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Component.For <ISessionFactory>()
                .UsingFactoryMethod(kernel => PersistanceEngine.CreateSessionFactory <WebSessionContext>())
                .LifestyleSingleton()
                );

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddDistributedMemoryCache();
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                options.IdleTimeout = TimeSpan.FromSeconds(10);
                //options.CookieHttpOnly = true;
            });

            var container = new WindsorContainer();

            container.Register(
                Classes.FromAssemblyContaining <WebAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Classes.FromAssemblyContaining <MvcPagesAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Classes.FromAssemblyContaining <VisualAssertionsAssemblyIdentity>()
                .Where(type => type.GetInterfaces().Any())
                .WithServiceAllInterfaces()
                .LifestyleSingleton(),
                Component.For <ISessionFactory>()
                .UsingFactoryMethod(kernel => PersistanceEngine.CreateSessionFactory <AspCoreSessionContext>())
                .LifestyleSingleton()
                );
            ServiceLocator.Init(container);
            return(WindsorRegistrationHelper.CreateServiceProvider(container, services));
        }