Exemplo n.º 1
0
        protected void Application_Start()
        {
            MockVcapServices();
            OriginalServices = Environment.GetEnvironmentVariable("VCAP_SERVICES");

            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            ApplicationConfig.RegisterConfig("development");
            ApplicationConfig.ConfigureLogging();

            var builder = new ContainerBuilder();

            builder.RegisterOptions();
            builder.RegisterLogging(ApplicationConfig.Configuration);

            // Register all the controllers with Autofac
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // configure CredHub client
            var credHubOptions = ApplicationConfig.Configuration.GetSection("CredHubClient").Get <CredHubOptions>();

            credHubOptions.Validate();
            builder.RegisterInstance(credHubOptions);
            var credHubClient = Steeltoe.Security.DataProtection.CredHub.CredHubClient.CreateUAAClientAsync(credHubOptions).GetAwaiter().GetResult();

            builder.RegisterInstance(credHubClient).As <ICredHubClient>().SingleInstance();

            // Create the Autofac container
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }