// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(typeof(AutoMapperProfile).GetTypeInfo().Assembly);

            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(RequestPreProcessorBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(RequestValidationBehavior <,>));

            services.AddMediatR(typeof(CreateScriptCommandHandler).GetTypeInfo().Assembly);
            services.AddMediatR(typeof(CognitoSignUpCommand).GetTypeInfo().Assembly);

            services.AddHttpClient();

            services.AddEntityFrameworkNpgsql().AddDbContext <RsPeerContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Postgres"),
                                  options => { options.MigrationsAssembly(typeof(Startup).Assembly.FullName); });
                builder.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
            });

            services.AddSingleton <MongoContext>();
            services.AddSingleton <MongoMigrationHandler>();

            services.AddHangfire(config =>
                                 config.UsePostgreSqlStorage(Configuration.GetConnectionString("Postgres")));

            services.AddMemoryCache();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <CreateScriptCommandHandler>());

            services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });

            EntityMapperExtensions.AddEntityMappers();
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddSentry();
                loggingBuilder.AddApplicationInsights(Configuration.GetValue <string>("ApplicationInsights:InstrumentationKey"));
            });

            services.AddAutoMapper(typeof(AutoMapperProfile).GetTypeInfo().Assembly);

            services.AddMediatR(typeof(CreateScriptCommandHandler).GetTypeInfo().Assembly,
                                typeof(CognitoSignUpCommand).GetTypeInfo().Assembly,
                                typeof(RegisterJobsCommand).GetTypeInfo().Assembly);

            services.AddHttpClient();

            services.AddEntityFrameworkNpgsql();

            services.AddDbContextPool <RsPeerContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Postgres"),
                                  options => { options.MigrationsAssembly(typeof(Startup).Assembly.FullName); });
            });

            services.AddDbContext <DiscourseContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Discourse"));
            });

            services.AddSingleton <IGitlabService, GitLabService>();
            services.AddSingleton <IRedisPubSubListener, RedisPubSubCommandHandler>();
            services.AddScoped <IBotLauncherService, BotLauncherService>();
            services.AddSingleton <IRedisService, RedisService>();
            services.AddSingleton <IDashboardAuthorizationFilter, HangfireDashboardAuthorizationFilter>();
            services.AddScoped <DaxWalkerService>();
            services.AddScoped <AcuityWalkerService>();

            services.AddMemoryCache();

            services.AddCors(o => o.AddPolicy("AllowCors", builder =>
            {
                builder
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin();
            }));

            // Jobs
            services.AddScoped <InstanceCloseJob>();
            services.AddScoped <SetClientCountJob>();
            services.AddScoped <SaveIpAccess>();
            services.AddScoped <SetTrueScriptCounts>();
            services.AddScoped <CheckInuvationAccess>();
            services.AddScoped <SendDiscordAlerts>();
            services.AddScoped <ClearMessagesJob>();
            services.AddScoped <ArchiveRunescapeClients>();

            services.AddSingleton <IFileStorage, SpacesService>();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders =
                    ForwardedHeaders.All;
                var cloudflare = Configuration.GetValue <string>("Cloudflare:IpList").Split(",").Select(w => w.Split("/")[0]).Select(IPAddress.Parse).ToList();
                cloudflare.ForEach(ip => options.KnownProxies.Add(ip));
            });

            services.AddControllers()
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            })
            .AddJsonOptions(w =>
            {
                w.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
            });

            services.AddHangfire(config =>
            {
                config.UsePostgreSqlStorage(Configuration.GetConnectionString("Postgres"), new PostgreSqlStorageOptions
                {
                    PrepareSchemaIfNecessary = false
                });
            });

            services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });


            services.AddSingleton <IDiscordSocketClientProvider, DiscordSocketClientProvider>();
            services.AddSingleton <DiscordRoleHelper>();

            services.AddSingleton <IUserFactory, SentryUserFactory>();

            services.AddScoped <ISendGridClient>(a =>
            {
                var config = a.GetService <IConfiguration>();
                return(new SendGridClient(config.GetValue <string>("SendGrid:ApiKey")));
            });

            EntityMapperExtensions.AddEntityMappers();
        }