예제 #1
0
        public static Container GetInitializeContainer(
            IAppBuilder app)
        {
            var container = new Container();

            container.Options.PropertySelectionBehavior = new ImportPropertySelectionBehavior(); // Enable ImportAttribute for property injection

            container.RegisterSingleton(app);

            container.Register <IFederationService, FederationService>(Lifestyle.Singleton);
            container.Register <IAppService, AppService>(Lifestyle.Transient);
            container.Register <IProviderLimiterService>(() =>
            {
                var service = new QueryParameterProviderLimiterService();
                service.Init(WebConfigurationManager.AppSettings);
                return(service);
            });

            container.RegisterConditional(typeof(IRepository <>), typeof(Repository <>), c => !c.Handled);

            container.Register <ICheckPasswordService <AppMember>, LegacyCheckPasswordService <AppMember> >(Lifestyle.Transient);

            container.RegisterPerWebRequest <IDragonUserStore <AppMember> >(() =>
            {
                var dragonUserStores = new List <IDragonUserStore <AppMember> >
                {
                    new UserStore <AppMember>(new Repository <AppMember>(), null, new Repository <IdentityUserLogin>(),
                                              new Repository <IdentityUserService>(), new Repository <IdentityUserApp>())
                };
                if (WebConfigurationManager.ConnectionStrings[RedisConnectionStringName] != null)
                {
                    var connectionMultiplexer = ConnectionMultiplexer.Connect(WebConfigurationManager.ConnectionStrings[RedisConnectionStringName].ConnectionString);
                    connectionMultiplexer.PreserveAsyncOrder = false;
                    dragonUserStores.Insert(0, new Identity.Redis.UserStore <AppMember>(new RedisUserStore <Identity.Redis.IdentityUser>(connectionMultiplexer), connectionMultiplexer));
                }
                var userStore = new ChainedIdentity.Stores.UserStore <AppMember>(dragonUserStores);
                Startup.OpenIdMigrationWebrequestHandler = new OpenIdMigrationWebRequestHandler(userStore);
                return(userStore);
            });

            container.Register <IUserService, UserService>(Lifestyle.Transient);

            container.RegisterPerWebRequest(() => ApplicationUserManager.Create(container, Startup.DataProtectionProvider));

            container.RegisterPerWebRequest(() => container.GetOwinContext().Authentication);

            container.RegisterMvcControllers(
                Assembly.GetExecutingAssembly());

            return(container);
        }
예제 #2
0
        public static Container GetInitializeContainer(
                  IAppBuilder app)
        {
            var container = new Container();
            container.Options.PropertySelectionBehavior = new ImportPropertySelectionBehavior(); // Enable ImportAttribute for property injection
 
            container.RegisterSingleton(app);

            container.Register<IFederationService, FederationService>(Lifestyle.Singleton);
            container.Register<IAppService, AppService>(Lifestyle.Transient);
 
            container.RegisterConditional(typeof(IRepository<>), typeof(Repository<>), c => !c.Handled);

            container.Register<ICheckPasswordService<AppMember>, LegacyCheckPasswordService<AppMember>>(Lifestyle.Transient);
 
            container.RegisterPerWebRequest<IDragonUserStore<AppMember>>(() =>
            {
                var dragonUserStores = new List<IDragonUserStore<AppMember>>
                {
                    new UserStore<AppMember>(new Repository<AppMember>(), null, new Repository<IdentityUserLogin>(),
                        new Repository<IdentityUserService>(), new Repository<IdentityUserApp>())
                };
                if (WebConfigurationManager.ConnectionStrings[RedisConnectionStringName] != null)
                {
                    var connectionMultiplexer = ConnectionMultiplexer.Connect(WebConfigurationManager.ConnectionStrings[RedisConnectionStringName].ConnectionString);
                    connectionMultiplexer.PreserveAsyncOrder = false;
                    dragonUserStores.Insert(0, new Identity.Redis.UserStore<AppMember>(new RedisUserStore<Identity.Redis.IdentityUser>(connectionMultiplexer), connectionMultiplexer));
                }
                var userStore = new ChainedIdentity.Stores.UserStore<AppMember>(dragonUserStores);
                Startup.OpenIdMigrationWebrequestHandler = new OpenIdMigrationWebRequestHandler(userStore);
                return userStore;
            });

            container.Register<IUserService, UserService>(Lifestyle.Transient);

            container.RegisterPerWebRequest(() => ApplicationUserManager.Create(container, Startup.DataProtectionProvider));

            container.RegisterPerWebRequest(() => container.GetOwinContext().Authentication);

            container.RegisterMvcControllers(
                    Assembly.GetExecutingAssembly());
            
            return container;
        }