Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHealthChecks()
            .AddCheck("self", () => HealthCheckResult.Healthy());

            services.AddControllers();

            // Configure API versioning
            services.AddApiVersioning(o => { o.ReportApiVersions = true; });
            services.AddVersionedApiExplorer(o =>
            {
                o.GroupNameFormat           = "'v'VVV";
                o.SubstituteApiVersionInUrl = true;
            });

            // Configure Swagger (OpenAPI doc generation)
            services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>();
            services.AddSwaggerGen(o =>
            {
                o.OperationFilter <SwaggerDefaultValues>();
                o.IncludeXmlComments(XmlCommentsFilePath);
            });

            services.AddSingleton <IMyCache>(_ => {
                MyCache.InitializeConnectionString(Configuration["CacheConnectionString"]);
                return(new MyCache());
            });

            services.AddSingleton <IMyDataStore>(_ => {
                return(new MyDataStore(Configuration["CosmosEndpointURL"], Configuration["CosmosKey"]));
            });

            services.AddScoped <WeatherService>();

            services.AddHttpContextAccessor();
        }