Skip to content

Commit 7add1c6

Browse files
Explicitly configure DbContextOptions
Set ConnectionMode.Gateway and LimitToEndpoint = true. Set relatively short RequestTimeout (10 seconds) to fail fast.
1 parent c94851a commit 7add1c6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Examples/CosmosDbExample/Startup.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
using Microsoft.AspNetCore.Authentication;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Hosting;
9+
using Microsoft.Azure.Cosmos;
910
using Microsoft.EntityFrameworkCore;
1011
using Microsoft.Extensions.Configuration;
1112
using Microsoft.Extensions.DependencyInjection;
1213
using Microsoft.Extensions.Logging;
1314

15+
#pragma warning disable AV2310 // Code block should not contain inline comment
16+
1417
namespace CosmosDbExample
1518
{
1619
public sealed class Startup
@@ -35,7 +38,14 @@ public void ConfigureServices(IServiceCollection services)
3538

3639
services.AddDbContext<AppDbContext>(options =>
3740
{
38-
options.UseCosmos(_connectionString, "TodoItemDB");
41+
options.UseCosmos(_connectionString, "TodoItemDB", builder =>
42+
{
43+
builder.ConnectionMode(ConnectionMode.Gateway);
44+
builder.LimitToEndpoint();
45+
46+
// Fail fast!
47+
builder.RequestTimeout(TimeSpan.FromSeconds(10));
48+
});
3949
#if DEBUG
4050
options.EnableSensitiveDataLogging();
4151
options.EnableDetailedErrors();

0 commit comments

Comments
 (0)