Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SetupApplicationInsightsFilters();

            services.AddCors();

            SetupAuthentication(services);

            // Add framework services.
            services.
            AddMvc(mvcOptions =>
            {
                mvcOptions.EnableEndpointRouting = false;
            }).
            AddNewtonsoftJson(jsonOptions =>
            {
                jsonOptions.SerializerSettings.DateFormatString     = "yyyy'-'MM'-'dd'T'HH':'mm':'ssK";
                jsonOptions.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            });

            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(Configuration.GetSection("Logging"));
                loggingBuilder.SetMinimumLevel(HostEnvironment.IsProduction() ? LogLevel.Warning : LogLevel.Information);
                loggingBuilder.AddConsole();
                loggingBuilder.AddDebug();
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v2", new OpenApiInfo {
                    Version = "v2",
                    Title   = "Relisten API",
                    Contact = new OpenApiContact {
                        Name = "Alec Gorge",
                        Url  = new Uri("https://twitter.com/alecgorge")
                    },
                    License = new OpenApiLicense {
                        Name = "MIT",
                        Url  = new Uri("https://opensource.org/licenses/MIT")
                    }
                });
            });

            Dapper.SqlMapper.AddTypeHandler(new Api.Models.PersistentIdentifierHandler());
            Dapper.SqlMapper.AddTypeHandler(new Api.Models.DateTimeHandler());

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            var db = new DbService(Configuration["DATABASE_URL"], HostEnvironment);

            RunMigrations(db);
            services.AddSingleton(db);

            var configurationOptions = RedisService.BuildConfiguration(Configuration["REDIS_URL"]);

            // use the static property because it is formatted correctly for NpgSQL
            services.AddHangfire(hangfire => {
                // processed into a connection string
                // hangfire.UsePostgreSqlStorage(DbService.ConnStr);

                hangfire.UseRedisStorage(ConnectionMultiplexer.Connect(configurationOptions), new RedisStorageOptions()
                {
                    InvisibilityTimeout = TimeSpan.FromHours(4)
                });
                hangfire.UseConsole();
                hangfire.UseRecurringJob(typeof(ScheduledService));
            });

            services.AddSingleton(new RedisService(configurationOptions));
            services.AddSingleton(Configuration);

            services.AddScoped <SetlistShowService, SetlistShowService>();
            services.AddScoped <VenueService, VenueService>();
            services.AddScoped <TourService, TourService>();
            services.AddScoped <SetlistSongService, SetlistSongService>();
            services.AddScoped <SetlistFmImporter, SetlistFmImporter>();
            services.AddScoped <PhishinImporter, PhishinImporter>();
            services.AddScoped <ShowService, ShowService>();
            services.AddScoped <ArchiveOrgImporter, ArchiveOrgImporter>();
            services.AddScoped <SourceService, SourceService>();
            services.AddScoped <SourceReviewService, SourceReviewService>();
            services.AddScoped <SourceSetService, SourceSetService>();
            services.AddScoped <SourceTrackService, SourceTrackService>();
            services.AddScoped <PhishNetImporter, PhishNetImporter>();
            services.AddScoped <PhantasyTourImporter, PhantasyTourImporter>();
            services.AddScoped <YearService, YearService>();
            services.AddScoped <EraService, EraService>();
            services.AddScoped <ImporterService, ImporterService>();
            services.AddScoped <JerryGarciaComImporter, JerryGarciaComImporter>();
            services.AddScoped <PanicStreamComImporter, PanicStreamComImporter>();
            services.AddScoped <ArtistService, ArtistService>();
            services.AddScoped <UpstreamSourceService, UpstreamSourceService>();
            services.AddScoped <ScheduledService, ScheduledService>();
            services.AddScoped <SearchService, SearchService>();
            services.AddScoped <LinkService, LinkService>();
            services.AddScoped <SourceTrackPlaysService, SourceTrackPlaysService>();
        }