templates/todo/api/csharp-cosmos-sql/Program.cs (35 lines of code) (raw):

using Azure.Identity; using Microsoft.Azure.Cosmos; using SimpleTodo.Api; var credential = new DefaultAzureCredential(); var builder = WebApplication.CreateBuilder(args); builder.Services.AddSingleton<ListsRepository>(); builder.Services.AddSingleton(_ => new CosmosClient(builder.Configuration["AZURE_COSMOS_ENDPOINT"], credential, new CosmosClientOptions() { SerializerOptions = new CosmosSerializationOptions { PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase } })); builder.Services.AddCors(); builder.Services.AddApplicationInsightsTelemetry(builder.Configuration); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseCors(policy => { policy.AllowAnyOrigin(); policy.AllowAnyHeader(); policy.AllowAnyMethod(); }); // Swagger UI app.UseSwaggerUI(options => { options.SwaggerEndpoint("./openapi.yaml", "v1"); options.RoutePrefix = ""; }); app.UseStaticFiles(new StaticFileOptions{ // Serve openapi.yaml file ServeUnknownFileTypes = true, }); app.MapGroup("/lists") .MapTodoApi() .WithOpenApi(); app.Run();