dotnet / docs-aspire

This repository contains .NET Aspire documentation.
https://learn.microsoft.com/dotnet/aspire
MIT License
87 stars 113 forks source link

Improve connection names for readability #2165

Open killnine opened 4 days ago

killnine commented 4 days ago

Type of issue

Other (describe below)

Description

In the Example Usage section of the EF Core page, the integration-consuming project gets an example:

builder.AddSqlServerDbContext<YourDbContext>("sqldb")

This is a very concise description. However, look at it in conjunction with the App Host project configuration of the database:

var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServer("sql")
                 .WithLifetime(ContainerLifetime.Persistent);

var db = sql.AddDatabase("database");

builder.AddProject<Projects.ExampleProject>()
       .WithReference(db);

// After adding all resources, run the app...

In this example, "database" and "sqldb" could be named the same thing to convey the fact that how the hosting integration names the database must match how the client integration names the database as well.

This point is covered well in this community video by Codewrinkles

My recommendation is:

builder.AddSqlServerDbContext<YourDbContext>("sqldb")
var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServer("sqlserver")
                 .WithLifetime(ContainerLifetime.Persistent);

var db = sql.AddDatabase("sqldb");

builder.AddProject<Projects.ExampleProject>()
       .WithReference(db);

// After adding all resources, run the app...

Page URL

https://learn.microsoft.com/en-us/dotnet/aspire/database/sql-server-entity-framework-integration?tabs=dotnet-cli%2Cssms

Content source URL

https://github.com/dotnet/docs-aspire/blob/main/docs/database/sql-server-entity-framework-integration.md

Document Version Independent Id

bf3e4e4b-039e-29fa-f9f0-3512be634ca8

Article author

@CamSoper

davidfowl commented 4 days ago

cc @IEvangelist