Exemple #1
0
        public static UnityContainer RegisterComponents(IDataProtectionProvider dataProtectionProvider)
        {
            var container = new UnityContainer();

            DiContainerHelper.RegisterComponents <HierarchicalLifetimeManager>(container);

            container.RegisterType <SignInManager <ApplicationUser, string>, ApplicationSignInManager>(new HierarchicalLifetimeManager());
            container.RegisterType <IUserStore <ApplicationUser>, UserStore <ApplicationUser> >(new HierarchicalLifetimeManager());
            container.RegisterType <UserManager <ApplicationUser>, ApplicationUserManager>(new HierarchicalLifetimeManager());
            container.RegisterType <Cache, Cache>(new InjectionFactory(o => HttpContext.Current.Cache));
            container.RegisterType <IAuthenticationManager>(new InjectionFactory(o => HttpContext.Current.GetOwinContext().Authentication));

            container.RegisterType <IdentityFactoryOptions <ApplicationUserManager> >(
                new InjectionFactory(o => new IdentityFactoryOptions <ApplicationUserManager>
            {
                DataProtectionProvider = dataProtectionProvider
            }));

            container.RegisterType <ISecureDataFormat <AuthenticationTicket>, SecureDataFormat <AuthenticationTicket> >();
            container.RegisterType <IDataSerializer <AuthenticationTicket>, TicketSerializer>();
            container.RegisterType <ITextEncoder, Base64UrlTextEncoder>();
            container.RegisterType <IDataProtector>(new InjectionFactory(o => dataProtectionProvider.Create()));

            DependencyResolver.SetResolver(new MvcUnityDependencyResolver(container));
            //GlobalConfiguration.Configuration.DependencyResolver = new MvcUnityDependencyResolver(container);
            //DependencyResolver.SetResolver(new UnityDependencyResolver(container));
            return(container);
        }
        public static UnityContainer RegisterComponents(IDataProtectionProvider dataProtectionProvider)
        {
            var container = new UnityContainer();

            DiContainerHelper.RegisterComponents <HierarchicalLifetimeManager>(container);

            var settings = new JsonSerializerSettings();

#if DEBUG
            settings.Formatting = Formatting.Indented;
#else
            settings.Formatting = Formatting.None;
#endif
            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            var jsonSerializer = JsonSerializer.Create(settings);
            container.RegisterInstance(jsonSerializer);

            DependencyResolver.SetResolver(new MvcUnityDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new WebApiUnityDependencyResolver(container);

            return(container);
        }