Skip to content

Commit

Permalink
Remove sample integration bits, not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Sep 17, 2024
1 parent 025ac88 commit 0b21e51
Showing 1 changed file with 0 additions and 112 deletions.
112 changes: 0 additions & 112 deletions docs/fundamentals/integrations-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,118 +165,6 @@ The following section details the available .NET Aspire client integrations, lin

For more information on working with .NET Aspire integrations in Visual Studio, see [Visual Studio tooling](setup-tooling.md#visual-studio-tooling).

## Explore a sample integration workflow

.NET Aspire integrations streamline the process of consuming popular services and platforms. For example, consider the **.NET Aspire project** template. With this template, you get the [AppHost](app-host-overview.md) and [ServiceDefaults](service-defaults.md) projects. Imagine that you have a need for a worker service to perform some database processing. You could use the [.NET Aspire PostgreSQL integration](../database/postgresql-integration.md) to connect to and utilize a PostgreSQL database. The database could be hosted on-premises or in a cloud service such as Azure, Amazon Web Services (AWS), or Google Cloud Platform (GCP). The following steps demonstrate how to integrate this integration into your app:

1. In the integration consuming (worker service) project, install the [Aspire.Npgsql](https://www.nuget.org/packages/Aspire.Npgsql) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Npgsql
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Npgsql" Version="[SelectVersion]" />
```

---

For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-package) or [Manage package dependencies in .NET applications](/dotnet/core/tools/dependencies).

1. In the _:::no-loc text="Program.cs":::_ file of your worker service project, call the <xref:Microsoft.Extensions.Hosting.AspirePostgreSqlNpgsqlExtensions.AddNpgsqlDataSource%2A> extension method to register `NpgsqlDataSource` as a service.

:::code source="snippets/integrations/AspireApp/WorkerService/Program.cs" highlight="5":::

The preceding code adds the `NpgsqlDataSource` to the dependency injection container with the connection name of `"customers"`. The connection name is later used by the orchestrator project, when expressing resource dependencies.

> [!TIP]
> Integrations that are designed to connect to Azure services also support passwordless authentication and authorization using [Azure RBAC](/azure/role-based-access-control/overview), which is the recommended approach for production apps.

1. In your app host project (the project with the _*.AppHost_ suffix), add a reference to the worker service project. If you're using Visual Studio, you can use the [**Add .NET Aspire Orchestrator Support**](setup-tooling.md#add-orchestration-projects) project context menu item to add the reference automatically. The following code snippet shows the project reference of the _AspireApp.AppHost.csproj_:

:::code language="xml" source="snippets/integrations/AspireApp/AspireApp.AppHost/AspireApp.AppHost.csproj" highlight="17":::

After the worker service is referenced by the orchestrator project, the worker service project has its _:::no-loc text="Program.cs":::_ file updated to call the `AddServiceDefaults` method. For more information on service defaults, see [Service defaults](service-defaults.md).

1. In the orchestrator project, update the _:::no-loc text="Program.cs":::_ file with the following code:

:::code source="snippets/integrations/AspireApp/AspireApp.AppHost/Program.cs" highlight="3-4,6-8":::

The preceding code:

- 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`.

1. Inject the `NpgsqlDataSource` object into the `Worker` to run commands against the database:

:::code source="snippets/integrations/AspireApp/WorkerService/Worker.cs" highlight="7,13":::

You now have a fully configured PostgreSQL database integration and corresponding container with connection integrated into your app. This integration also configured health checks, logging, metrics, retries, and other useful capabilities for you behind the scenes. .NET Aspire integrations provide various options to configure each of these features.

## Configure .NET Aspire integrations

.NET Aspire integrations implement a consistent configuration experience via <xref:Microsoft.Extensions.Configuration.IConfiguration> and <xref:Microsoft.Extensions.Options.IOptions%601>. Configuration is schematized and part of an integration's contract, ensuring backward compatibility across versions of the integration. You can set up every .NET Aspire integration through either JSON configuration files or directly through code using delegates. JSON files must follow a standardized naming convention based on the Component name.

For example, add the following code to the _:::no-loc text="appsettings.json":::_ file to configure the PostgreSQL integration:

```json
{
"Aspire": {
"Npgsql": {
"DisableHealthChecks": true,
"DisableTracing": true
}
}
}
```

Alternatively, you can configure the integration directly in your code using a delegate:

```csharp
builder.AddNpgsqlDataSource(
"PostgreSqlConnection",
static settings => settings.DisableHealthChecks = true);
```

## Dependency injection

.NET Aspire integrations automatically register essential services with the .NET dependency container using the proper scope. This allows key integration classes and services to be injected throughout your code. For example, the .NET Aspire PostgreSQL integration makes available the `NpgsqlDataSource` to inject into your application layers and run commands against a database:

```csharp
public class ExampleService(NpgsqlDataSource dataSource)
{
}
```

For more information, see [.NET dependency injection](/dotnet/core/extensions/dependency-injection).

### Keyed services

.NET Aspire integrations also support keyed dependency injection. In this scenario, the service name for keyed dependency injection is the same as the connection name:

```csharp
builder.AddKeyedNpgsqlDataSource(
"PostgreSqlConnection",
static settings => settings.DisableHealthChecks = true);
```

You can then retrieve the registered service using the <xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute>:

```csharp
public class ExampleService(
[FromKeyedServices("PostgreSqlConnection")] NpgsqlDataSource npgContext)
{
}
```

For more information, see [Dependency injection in .NET: Keyed services](/dotnet/core/extensions/dependency-injection#keyed-services).

## Cloud-native features

Cloud-native applications surface many unique requirements and concerns. The core features of .NET Aspire orchestration and integrations are designed to handle many cloud-native concerns for you with minimal configurations. Some of the key features include:
Expand Down

0 comments on commit 0b21e51

Please sign in to comment.