Skip to content

Commit

Permalink
Remove Container methods from AppHost docs (#274)
Browse files Browse the repository at this point in the history
* Remove Container methods from AppHost docs

It isn't recommended to use the "AddXYZContainer" methods, but instead just "AddXYZ". Using the Container methods means that you want a container even after publishing to a cloud service, which has hosted versions of these resources.

Contributes to dotnet/aspire#1528

* Update docs/database/snippets/tutorial/aspiresqlefcore/AspireSQLEFCore.AppHost/Program.cs

* Update app-host-overview.md

Fix xrefs

---------

Co-authored-by: David Pine <david.pine@microsoft.com>
  • Loading branch information
eerhardt and IEvangelist authored Jan 4, 2024
1 parent afc4742 commit 939fe6c
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/caching/caching-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Update the _Program.cs_ file of the `AspireRedis.AppHost` project to match the f
```csharp
var builder = DistributedApplication.CreateBuilder(args);

var redis = builder.AddRedisContainer("cache");
var redis = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireRedis_ApiService>("apiservice")
.WithReference(redis);
Expand Down
2 changes: 1 addition & 1 deletion docs/caching/stackexchange-redis-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ In your orchestrator project, register the .NET Aspire Stack Exchange Redis comp

```csharp
// Service registration
var redis = builder.AddRedisContainer("redis");
var redis = builder.AddRedis("redis");

// Service consumption
builder.AddProject<Projects.ExampleProject>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ builder.AddRedisDistributedCache(

## Orchestration

In your orchestrator project, register the .NET Aspire Stack Exchange Redis component and consume the service using the following methods, such as <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedisContainer%2A>:
In your orchestrator project, register the .NET Aspire Stack Exchange Redis component and consume the service using the following methods, such as <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedis%2A>:

```csharp
// Service registration
var redis = builder.AddRedisContainer("redis");
var redis = builder.AddRedis("redis");

// Service consumption
builder.AddProject<Projects.ExampleProject>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ In your orchestrator project, register the .NET Aspire StackExchange Redis outpu

```csharp
// Service registration
var redis = builder.AddRedisContainer("redis");
var redis = builder.AddRedis("redis");

// Service consumption
var basket = builder.AddProject<Projects.ExampleProject>()
Expand Down
4 changes: 2 additions & 2 deletions docs/database/mongodb-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ Here are the configurable options with corresponding default values:

## Orchestration

In your AppHost project, register a MongoDB container and consume the connection using the following methods:
In your AppHost project, register a MongoDB database and consume the connection using the following methods:

```csharp
var mongodb = builder.AddMongoDBContainer("mongodb")
var mongodb = builder.AddMongoDB("mongodb")
.AddDatabase("database");

var myService = builder.AddProject<Projects.MyService>()
Expand Down
4 changes: 2 additions & 2 deletions docs/database/mysql-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ Here are the configurable options with corresponding default values:

## Orchestration

In your AppHost project, register a SqlServer container and consume the connection using the following methods:
In your AppHost project, register a MySql database and consume the connection using the following methods:

```csharp
var mysqldb = builder.AddMySqlContainer("mysql")
var mysqldb = builder.AddMySql("mysql")
.AddDatabase("mysqldb");

var myService = builder.AddProject<Projects.MyService>()
Expand Down
4 changes: 2 additions & 2 deletions docs/database/postgresql-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ builder.AddNpgsqlDataSource(

## Orchestration

In your orchestrator project, register and consume the PostgreSQL component using the following methods, such as <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgresContainer%2A>:
In your orchestrator project, register and consume the PostgreSQL component using the following methods, such as <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgres%2A>:

```csharp
var postgresdb = builder.AddPostgresContainer("pg")
var postgresdb = builder.AddPostgres("pg")
.AddDatabase("postgresdb");

var exampleProject = builder.AddProject<Projects.ExampleProject>()
Expand Down
2 changes: 1 addition & 1 deletion docs/database/postgresql-entity-framework-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Here are the configurable options with corresponding default values:
In your orchestrator project, register the PostgreSQL component and consume the `DbContext` using the following methods:

```csharp
var postgresdb = builder.AddPostgresContainer("pg")
var postgresdb = builder.AddPostgres("pg")
.AddDatabase("postgresdb");

var myService = builder.AddProject<Projects.MyService>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var sqlpassword = builder.Configuration["sqlpassword"];

var sql = builder.AddSqlServerContainer("sql", sqlpassword).AddDatabase("sqldata");
var sql = builder.AddSqlServer("sql")
.AddDatabase("sqldata");

builder.AddProject<Projects.AspireSQLEFCore>("aspiresql")
.WithReference(sql);
Expand Down
4 changes: 2 additions & 2 deletions docs/database/sql-server-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ Here are the configurable options with corresponding default values:

## Orchestration

In your AppHost project, register a SqlServer container and consume the connection using the following methods:
In your AppHost project, register a SqlServer database and consume the connection using the following methods:

```csharp
var sql = builder.AddSqlServerContainer("sql")
var sql = builder.AddSqlServer("sql")
.AddDatabase("sqldata");

var myService = builder.AddProject<Projects.MyService>()
Expand Down
4 changes: 2 additions & 2 deletions docs/database/sql-server-entity-framework-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ Here are the configurable options with corresponding default values:

## Orchestration

In your AppHost project, register a SqlServer container and consume the connection using the following methods, such as <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServerContainer%2A>:
In your AppHost project, register a SqlServer database and consume the connection using the following methods, such as <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServer%2A>:

```csharp
var sql = builder.AddSqlServerContainer("sql")
var sql = builder.AddSqlServer("sql")
.AddDatabase("sqldata");

var myService = builder.AddProject<Projects.MyService>()
Expand Down
4 changes: 2 additions & 2 deletions docs/deployment/azure/aca-deployment-azd-in-depth.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ To see this in action, update the _Program.cs_ file in the AppHost project to th
```csharp
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");
// Add the locations database.
var locationsdb = builder.AddPostgresContainer("db").AddDatabase("locations");
var locationsdb = builder.AddPostgres("db").AddDatabase("locations");
// Add the locations database reference to the API service.
var apiservice = builder.AddProject<Projects.AspireAzdWalkthrough_ApiService>("apiservice")
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment/azure/application-insights.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var builder = DistributedApplication.CreateBuilder(args);
var appInsightsConnectionString =
builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"];

var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
.WithEnvironment(
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment/manifest-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ The `apiservice` resource is referenced by `webfrontend` using the call `WithRef
```csharp
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

Expand Down
14 changes: 7 additions & 7 deletions docs/fundamentals/app-host-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The app host project handles running all of the projects that are part of the .N
```csharp
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

Expand Down Expand Up @@ -68,7 +68,7 @@ var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
A reference represents a dependency between resources. Consider the following:

```csharp
var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithReference(cache);
Expand All @@ -81,13 +81,13 @@ The "webfrontend" project resource uses <xref:Aspire.Hosting.ResourceBuilderExte
It's also possible to have dependencies between project resources. Consider the following example code:

```csharp
var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithReference(cache)
.WithReference(apiservice);
.WithReference(apiservice);
```

Project-to-project references are handled differently than resources that have well defined connection strings. Instead of connection string being injected into the "webfrontend" resource, environment variables to support service discovery are injected.
Expand Down Expand Up @@ -133,12 +133,12 @@ Beyond the base resource types, <xref:Aspire.Hosting.ApplicationModel.ProjectRes
| `AddNpmApp(...)` | `NodeAppResource` | Adds a Node.js app resource that wraps an [NPM](https://www.npmjs.com/) package. |
| `AddPostgresContainer(...).`<xref:Aspire.Hosting.PostgresBuilderExtensions.AddDatabase%2A> | <xref:Aspire.Hosting.ApplicationModel.PostgresDatabaseResource> | Adds a Postgres database resource. |
| `AddSqlServerContainer(...).`<xref:Aspire.Hosting.SqlServerBuilderExtensions.AddDatabase%2A> | <xref:Aspire.Hosting.ApplicationModel.SqlServerDatabaseResource> | Adds a SQL Server database resource. |
| <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgresConnection%2A> | <xref:Aspire.Hosting.ApplicationModel.PostgresConnectionResource> | Adds a Postgres connection resource. |
| <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgres%2A> | <xref:Aspire.Hosting.ApplicationModel.PostgresServerResource> | Adds a Postgres server resource. |
| <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgresContainer%2A> | <xref:Aspire.Hosting.ApplicationModel.PostgresContainerResource> | Adds a Postgres container resource. |
| <xref:Aspire.Hosting.RabbitMQBuilderExtensions.AddRabbitMQConnection%2A> | <xref:Aspire.Hosting.ApplicationModel.RabbitMQConnectionResource> | Adds a RabbitMQ connection resource. |
| <xref:Aspire.Hosting.RabbitMQBuilderExtensions.AddRabbitMQ%2A> | <xref:Aspire.Hosting.ApplicationModel.RabbitMQServerResource> | Adds a RabbitMQ server resource. |
| <xref:Aspire.Hosting.RabbitMQBuilderExtensions.AddRabbitMQContainer%2A> | <xref:Aspire.Hosting.ApplicationModel.RabbitMQContainerResource> | Adds a RabbitMQ container resource. |
| <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedisContainer%2A> | <xref:Aspire.Hosting.ApplicationModel.RedisContainerResource> | Adds a Redis container resource. |
| <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServerConnection%2A> | <xref:Aspire.Hosting.ApplicationModel.SqlServerConnectionResource> | Adds a SQL Server connection resource. |
| <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServer%2A> | <xref:Aspire.Hosting.ApplicationModel.SqlServerServerResource> | Adds a SQL Server server resource. |
| <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServerContainer%2A> | <xref:Aspire.Hosting.ApplicationModel.SqlServerContainerResource> | Adds a SQL Server container resource. |

**Azure specific resources available in the [📦 Aspire.Hosting.Azure](https://www.nuget.org/packages/Aspire.Hosting.Azure) NuGet package:**
Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/components-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ For more information on working with .NET Aspire components in Visual Studio, se

The preceding code:

- Calls <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgresContainer%2A> and chains a call to <xref:Aspire.Hosting.PostgresBuilderExtensions.AddDatabase%2A>, adding a PostgreSQL database container to the app model with a database named `"customers"`.
- Calls <xref:Aspire.Hosting.PostgresBuilderExtensions.AddPostgres%2A> and chains a call to <xref:Aspire.Hosting.PostgresBuilderExtensions.AddDatabase%2A>, adding a PostgreSQL database container to the app model with a database named `"customers"`.
- Chains calls on the result of the <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A> from the worker service project:
- Calls <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A> to add a reference to the `database`.
- Calls <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.WithReplicas%2A> to set the number of replicas to `3`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var builder = DistributedApplication.CreateBuilder(args);

var database = builder.AddPostgresContainer("postgresql")
var database = builder.AddPostgres("postgresql")
.AddDatabase("customers");

builder.AddProject<Projects.WorkerService>("workerservice")
Expand Down
6 changes: 3 additions & 3 deletions docs/get-started/aspire-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ For example, using .NET Aspire, the following code creates a local Redis contain
// Create a distributed application builder given the command line arguments.
var builder = DistributedApplication.CreateBuilder(args);

// Add a Redis container to the application.
var cache = builder.AddRedisContainer("cache");
// Add a Redis server to the application.
var cache = builder.AddRedis("cache");

// Add the frontend project to the application and configure it to use the
// Redis container, defined as a referenced dependency.
// Redis server, defined as a referenced dependency.
builder.AddProject<Projects.MyFrontend>("frontend")
.WithReference(cache);
```
Expand Down
4 changes: 2 additions & 2 deletions docs/get-started/build-your-first-aspire-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Consider the _Program.cs_ file of the _AspireSample.AppHost_ project:
If you've used either the [.NET Generic Host](/dotnet/core/extensions/generic-host) or the [ASP.NET Core Web Host](/aspnet/core/fundamentals/host/web-host) before, the app host programming model and builder pattern should be familiar to you. The preceding code:

- Creates an <xref:Aspire.Hosting.IDistributedApplicationBuilder> instance from calling <xref:Aspire.Hosting.DistributedApplication.CreateBuilder?displayProperty=nameWithType>.
- Calls <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedisContainer%2A> with the name `"cache"` to add a Redis container to the app, assigning the returned value to a variable named `cache`, which is of type `IResourceBuilder<RedisContainerResource>`.
- Calls <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedis%2A> with the name `"cache"` to add a Redis server to the app, assigning the returned value to a variable named `cache`, which is of type `IResourceBuilder<RedisResource>`.
- Calls <xref:Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject%2A> given the generic-type parameter with the project's <xref:Aspire.Hosting.IServiceMetadata> details, adding the `AspireSample.ApiService` project to the application model. This is one of the fundamental building blocks of .NET Aspire, and it's used to configure service discovery and communication between the projects in your app. The name argument `"apiservice"` is used to identify the project in the application model, and used later by projects that want to communicate with it.
- Calls `AddProject` again, this time adding the `AspireSample.Web` project to the application model. It also chains multiple calls to <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A> passing the `cache` and `apiservice` variables. The `WithReference` API is another fundamental API of .NET Aspire, which injects either service discovery information or connection string configuration into the project being added to the application model.

Expand All @@ -69,7 +69,7 @@ The service defaults project exposes an extension method on the <xref:Microsoft.

## Orchestrate service communication

.NET Aspire provides orchestration features to assist with configuring connections and communication between the different parts of your app. The _AspireSample.AppHost_ project added the _AspireSample.ApiService_ and _AspireSample.Web_ projects to the application model. It also declared their names as `"webfrontend"` for Blazor front end, `"apiservice"` for the API project reference. Additionally, a Redis container resource labelled `"cache"` was added. These names are used to configure service discovery and communication between the projects in your app.
.NET Aspire provides orchestration features to assist with configuring connections and communication between the different parts of your app. The _AspireSample.AppHost_ project added the _AspireSample.ApiService_ and _AspireSample.Web_ projects to the application model. It also declared their names as `"webfrontend"` for Blazor front end, `"apiservice"` for the API project reference. Additionally, a Redis server resource labelled `"cache"` was added. These names are used to configure service discovery and communication between the projects in your app.

The front end app defines a typed <xref:System.Net.Http.HttpClient> that's used to communicate with the API project.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedisContainer("cache");
var cache = builder.AddRedis("cache");

var apiservice = builder.AddProject<Projects.AspireSample_ApiService>("apiservice");

Expand Down
4 changes: 2 additions & 2 deletions docs/messaging/rabbitmq-client-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ builder.AddRabbitMQ(

## Orchestration

In your orchestrator project, register a RabbitMQ container and consume the connection using the following methods, such as <xref:Aspire.Hosting.RabbitMQBuilderExtensions.AddRabbitMQContainer%2A>:
In your orchestrator project, register a RabbitMQ server and consume the connection using the following methods, such as <xref:Aspire.Hosting.RabbitMQBuilderExtensions.AddRabbitMQ%2A>:

```csharp
// Service registration
var messaging = builder.AddRabbitMQContainer("messaging");
var messaging = builder.AddRabbitMQ("messaging");

// Service consumption
builder.AddProject<Projects.ExampleProject>()
Expand Down

0 comments on commit 939fe6c

Please sign in to comment.