Esempio n. 1
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <MongoContext>().AsImplementedInterfaces <MongoContext, ConcreteReflectionActivatorData>().SingleInstance();

            builder.RegisterType <AuthRepository>().SingleInstance();
            builder.RegisterType <CalculatorRepository>().SingleInstance();
            //builder.RegisterType<CalculatorRepository>()
            //    .WithParameters(new Parameter[]
            //    {
            //        new ResolvedParameter((info, context) => info.Name == "mongoContext",
            //            (info, context) => context.Resolve<IMongoContext>()),
            //        new ResolvedParameter((info, context) => info.Name == "userManager",
            //            (info, context) => context.Resolve<ApplicationUserManager>())
            //    }).SingleInstance();

            builder.RegisterType <ApplicationIdentityContext>()
            .SingleInstance();

            builder.RegisterType <UserStore <User> >()
            .AsImplementedInterfaces <IUserStore <User>, ConcreteReflectionActivatorData>()
            .SingleInstance();

            builder.RegisterType <RoleStore <Role> >()
            .AsImplementedInterfaces <IRoleStore <Role>, ConcreteReflectionActivatorData>()
            .SingleInstance();

            builder.RegisterType <ApplicationUserManager>()
            .SingleInstance();

            builder.RegisterType <ApplicationRoleManager>()
            .SingleInstance();

            builder.RegisterType <SimpleAuthorizationServerProvider>()
            .AsImplementedInterfaces <IOAuthAuthorizationServerProvider, ConcreteReflectionActivatorData>().SingleInstance();

            builder.RegisterType <SimpleRefreshTokenProvider>()
            .AsImplementedInterfaces <IAuthenticationTokenProvider, ConcreteReflectionActivatorData>().SingleInstance();

            //builder.RegisterType<SimpleAuthorizationServerProvider>()
            //    .AsImplementedInterfaces<IOAuthAuthorizationServerProvider, ConcreteReflectionActivatorData>()
            //    .WithParameters(new Parameter[]
            //    {
            //        new NamedParameter("publicClientId", "self"),
            //        new ResolvedParameter((info, context) => info.Name == "userManager",
            //            (info, context) => context.Resolve<ApplicationUserManager>())
            //    });

            builder.RegisterApiControllers(typeof(Startup).Assembly);

            var container = builder.Build();

            app.UseAutofacMiddleware(container);

            var webApiDependencyResolver = new AutofacWebApiDependencyResolver(container);

            var configuration = new HttpConfiguration
            {
                DependencyResolver = webApiDependencyResolver
            };

            ConfigureOAuth(app, container);

            WebApiConfig.Register(configuration);

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            app.UseWebApi(configuration);

            app.UseAutofacWebApi(configuration);

            InitializeData(container);
        }