示例#1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <StravaAppConfig>(Configuration.GetSection("StravaApp"));
            services.Configure <DarkSkyConfig>(Configuration.GetSection("DarkSky"));

            services.AddDbContext <Database>(options =>
            {
                var databaseUrl = this.Configuration["DATABASE_URL"];
                if (string.IsNullOrEmpty(databaseUrl))
                {
                    Console.WriteLine("Using in-memory db");
                    options.UseInMemoryDatabase("strava-weather");
                }
                else
                {
                    Console.WriteLine($"Using postgres db");
                    options.UseNpgsql(DatabaseUtil.ConvertDatabaseConnectionString(databaseUrl));
                }
            });

            services.AddMvc(config => { config.Filters.Add(typeof(ExceptionHandler)); });

            services.AddSingletonFactory <StravaAuthApi, StravaAuthApiFactory>();
            services.AddSingletonFactory <StravaApi, StravaApiFactory>();
            services.AddSingletonFactory <DarkSkyApi, DarkSkyApiFactory>();
        }