public IContainer GetContainer() { if (BootstrapData == null) { BootstrapData = BootstrapApplication(); } var builder = new ContainerBuilder(); builder.RegisterWebPortal(); // You'll need to have an AWS profile configured in one of two ways: // 1) Ambient environment http://docs.aws.amazon.com/AWSSdkDocsNET/latest/DeveloperGuide/net-dg-config-creds.html // 2) EC2 IAM role // // The profile will need: // * EC2 access to describe the tags of the instance StackIt is running on // * S3 access to the bucket where the bootstrap config lives // * KMS access to the master key that's used for encrypting other AWS profiles builder.Register(context => AmbientCredentials.GetCredentials()).As<AWSCredentials>(); builder.Register(context => { var kmsClient = new AmazonKeyManagementServiceClient(context.Resolve<AWSCredentials>()); var masterKeyAlias = context.Resolve<IStackItConfiguration>().CloudOptions.MasterKeyAlias; return new EnvelopeCryptoProvider(kmsClient, string.Format("alias/{0}", masterKeyAlias)); }).As<ICryptoProvider>(); // At this point, the application is configured to use values supplied by app.config // However, if we're running on EC2 and bootstrap data was provided, // we need to overwrite some infrastructure-level registrations if (BootstrapData != null) { builder.RegisterType<BootstrapDatabaseConfiguration>().As<IDatabaseConfiguration>() .WithParameter("connectionString", BootstrapData.ApplicationDatabaseConnectionString); builder.RegisterType<BootstrapCrowdConfiguration>().As<ICrowdConfiguration>() .WithParameter("url", BootstrapData.CrowdUrl) .WithParameter("applicationName", BootstrapData.CrowdUsername) .WithParameter("apiPassword", BootstrapData.CrowdPassword); builder.RegisterType<BootstrapHangfireConfiguration>().As<IHangfireConfiguration>() .WithParameter("connectionString", BootstrapData.HangfireDatabaseConnectionString); } builder.Register(_ => EventBus.Instance).SingleInstance(); builder.RegisterHubWithLifetimeScope<EventBusHub>(); return builder.Build(); }