예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services
            .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(x =>
            {
                x.Authority            = GetAppSetting("IdentityServiceUrl");
                x.ApiName              = GetAppSetting("IdentityServiceApiName");
                x.ApiSecret            = GetAppSetting("IdentityServiceApiSecret");
                x.RequireHttpsMetadata = false;
            });

            services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
            services.AddAWSService <Amazon.S3.IAmazonS3>();

            var builder = new ContainerBuilder();

            builder.Populate(services);

            ContainerRegistrations.RegisterFor(builder);
            builder.RegisterType <ConnectionConfigProvider>().As <IDataConnectionConfigProvider>();
            builder.RegisterType <SqlConnectionStringProvider>().As <ISqlConnectionStringProvider>();
            builder.RegisterType <ClientConnectionInfoProvider>().As <IClientConnectionInfoProvider>();
            builder.RegisterInstance(Configuration).As <IConfiguration>();

            this.ApplicationContainer = builder.Build();

            // Create the IServiceProvider based on the container.
            return(new AutofacServiceProvider(this.ApplicationContainer));
        }
예제 #2
0
 // ConfigureContainer is where you can register things directly
 // with Autofac. This runs after ConfigureServices so the things
 // here will override registrations made in ConfigureServices.
 // Don't build the container; that gets done for you. If you
 // need a reference to the container, you need to use the
 // "Without ConfigureContainer" mechanism shown later.
 public void ConfigureContainer(ContainerBuilder builder)
 {
     // Register your own things directly with Autofac
     ContainerRegistrations.RegisterFor(builder, Configuration);
     builder.RegisterInstance(Configuration).As <IConfiguration>();
     //...
 }