コード例 #1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <QueueSettings>(Configuration.GetSection("QueueSettings"));
            services.Configure <TwitterAuthSettings>(Configuration.GetSection("TwitterAuthSettings"));
            services.Configure <TwitterApiSettings>(Configuration.GetSection("TwitterApiSettings"));
            services.Configure <HangfireSettings>(Configuration.GetSection("HangfireSettings"));

            var connectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddHangfire(config => config.UseSqlServerStorage(connectionString));
            services.AddMvc();

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder => builder.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()
                                                          .AllowCredentials()));

            var container = new AutofacModulesConfigurator().Configure(services);

            GlobalConfiguration.Configuration.UseActivator(new AutofacContainerJobActivator(container));

            return(container.Resolve <IServiceProvider>());
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <VkAuthSettings>(Configuration.GetSection("VkAuthSettings"));
            services.Configure <VkSettings>(Configuration.GetSection("VkSettings"));
            services.Configure <EndpointSettings>(Configuration.GetSection("EndpointSettings"));
            services.Configure <VkConsumeSettings>(Configuration.GetSection("VkConsumeSettings"));
            services.Configure <TwitterConsumeSettings>(Configuration.GetSection("TwitterConsumeSettings"));
            services.AddMvc(options =>
            {
                options.CacheProfiles.Add("Default",
                                          new CacheProfile
                {
                    Duration = 60
                });
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "HashtagAggregator", Version = "v1"
                });
            });

            services.AddMediatR(typeof(EfQueryHandler));
            var connectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;

            services.AddEntityFrameworkSqlServer()
            .AddDbContextPool <SqlApplicationDbContext>(options => options.UseSqlServer(connectionString));

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddScoped(sp => mapperConfiguration.CreateMapper());
            mapperConfiguration.AssertConfigurationIsValid();

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(o =>
            {
                o.Authority            = Configuration.GetSection("EndpointSettings:AuthEndpoint").Value;
                o.Audience             = "statisticsapi";
                o.RequireHttpsMetadata = false;
            });

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder => builder.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()
                                                          .AllowCredentials()));

            var container = new AutofacModulesConfigurator().Configure(services);

            return(container.Resolve <IServiceProvider>());
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <VkAuthSettings>(Configuration.GetSection("VkAuthSettings"));
            services.Configure <VkSettings>(Configuration.GetSection("VkSettings"));
            services.Configure <EndpointSettings>(Configuration.GetSection("EndpointSettings"));
            services.Configure <VkConsumeSettings>(Configuration.GetSection("VkConsumeSettings"));
            services.Configure <TwitterConsumeSettings>(Configuration.GetSection("TwitterConsumeSettings"));

            services.AddMvc(options =>
            {
                options.CacheProfiles.Add("Default",
                                          new CacheProfile
                {
                    Duration = 60
                });
            });
            services.AddMediatR(typeof(EfQueryHandler));
            var connectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;

            services.AddEntityFrameworkSqlServer()
            .AddDbContext <SqlApplicationDbContext>(options => options.UseSqlServer(connectionString));

            IDbSeeder dbSeeder = new DbSeeder();

            dbSeeder.Seed(connectionString);

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddScoped(sp => mapperConfiguration.CreateMapper());
            mapperConfiguration.AssertConfigurationIsValid();

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder => builder.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()
                                                          .AllowCredentials()));

            var container = new AutofacModulesConfigurator().Configure(services);
            var starter   = new ServiceStarter(container);

            starter.Start();
            return(container.Resolve <IServiceProvider>());
        }