-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 35038: Merge branch 'release/8.0-preview1' into 'internal/r…
- Loading branch information
Showing
37 changed files
with
1,547 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Aspire.Hosting.Azure/AzureCosmosDBCloudApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Hosting.ApplicationModel; | ||
using Aspire.Hosting.Azure.Data.Cosmos; | ||
using System.Text.Json; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
/// <summary> | ||
/// Provides extension methods for adding Azure Cosmos DB resources to an <see cref="IDistributedApplicationBuilder"/>. | ||
/// </summary> | ||
public static class AzureCosmosDBCloudApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds an Azure Cosmos DB connection to the application model. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param> | ||
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param> | ||
/// <param name="connectionString">The connection string.</param> | ||
/// <returns>A reference to the <see cref="IResourceBuilder{AzureCosmosDatabaseResource}"/>.</returns> | ||
public static IResourceBuilder<AzureCosmosDBConnectionResource> AddAzureCosmosDB( | ||
this IDistributedApplicationBuilder builder, | ||
string name, | ||
string? connectionString = null) | ||
{ | ||
var connection = new AzureCosmosDBConnectionResource(name, connectionString); | ||
return builder.AddResource(connection) | ||
.WithAnnotation(new ManifestPublishingCallbackAnnotation(jsonWriter => WriteCosmosDBConnectionToManifest(jsonWriter, connection))); | ||
} | ||
|
||
private static void WriteCosmosDBConnectionToManifest(Utf8JsonWriter jsonWriter, AzureCosmosDBConnectionResource cosmosDbConnection) | ||
{ | ||
jsonWriter.WriteString("type", "azure.cosmosdb.connection.v0"); | ||
jsonWriter.WriteString("connectionString", cosmosDbConnection.GetConnectionString()); | ||
} | ||
|
||
private static void WriteCosmosDBDatabaseToManifest(Utf8JsonWriter jsonWriter, AzureCosmosDatabaseResource cosmosDatabase) | ||
{ | ||
jsonWriter.WriteString("type", "azure.cosmosdb.database.v0"); | ||
jsonWriter.WriteString("parent", cosmosDatabase.Parent.Name); | ||
jsonWriter.WriteString("databaseName", cosmosDatabase.Name); | ||
} | ||
|
||
/// <summary> | ||
/// Adds an Azure Cosmos DB database to a <see cref="IResourceBuilder{AzureCosmosDatabaseResource}"/>. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param> | ||
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param> | ||
/// <returns>A reference to the <see cref="IResourceBuilder{AzureCosmosDatabaseResource}"/>.</returns> | ||
public static IResourceBuilder<AzureCosmosDatabaseResource> AddDatabase(this IResourceBuilder<AzureCosmosDBConnectionResource> builder, string name) | ||
{ | ||
var cosmosDatabase = new AzureCosmosDatabaseResource(name, builder.Resource); | ||
return builder | ||
.ApplicationBuilder | ||
.AddResource(cosmosDatabase) | ||
.WithAnnotation(new ManifestPublishingCallbackAnnotation( | ||
(json) => WriteCosmosDBDatabaseToManifest(json, cosmosDatabase))); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Aspire.Hosting.Azure/AzureCosmosDBConnectionResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace Aspire.Hosting.Azure.Data.Cosmos; | ||
|
||
/// <summary> | ||
/// Represents a connection to an Azure Cosmos DB account. | ||
/// </summary> | ||
/// <param name="name">The resource name.</param> | ||
/// <param name="connectionString">The connection string to use to connect.</param> | ||
public class AzureCosmosDBConnectionResource(string name, string? connectionString) | ||
: Resource(name), IResourceWithConnectionString | ||
{ | ||
/// <summary> | ||
/// Gets the connection string to use for this database. | ||
/// </summary> | ||
/// <returns>The connection string to use for this database.</returns> | ||
public string? GetConnectionString() => connectionString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace Aspire.Hosting.Azure.Data.Cosmos; | ||
|
||
/// <summary> | ||
/// Represents an Azure Cosmos DB database. | ||
/// </summary> | ||
/// <param name="name">The database name.</param> | ||
/// <param name="parent">The parent <see cref="AzureCosmosDBConnectionResource"/>.</param> | ||
public class AzureCosmosDatabaseResource(string name, AzureCosmosDBConnectionResource parent) | ||
: Resource(name), IResourceWithParent<AzureCosmosDBConnectionResource>, IResourceWithConnectionString | ||
{ | ||
/// <summary> | ||
/// Gets the parent <see cref="AzureCosmosDBConnectionResource"/>. | ||
/// </summary> | ||
public AzureCosmosDBConnectionResource Parent { get; } = parent; | ||
|
||
/// <summary> | ||
/// Gets the connection string to use for this database. | ||
/// </summary> | ||
/// <returns>The connection string to use for this database.</returns> | ||
public string? GetConnectionString() | ||
{ | ||
return Parent.GetConnectionString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Components/Aspire.Microsoft.Azure.Cosmos/Aspire.Microsoft.Azure.Cosmos.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(NetCurrent)</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<EnableConfigurationBindingGenerator>false</EnableConfigurationBindingGenerator> | ||
<IsAotCompatible>false</IsAotCompatible> | ||
<PackageTags>$(ComponentAzurePackageTags) cosmos cosmosdb data database db</PackageTags> | ||
<Description>A client for Azure Cosmos DB that integrates with Aspire, including logging and telemetry.</Description> | ||
<PackageIconFullPath>$(SharedDir)AzureCosmosDB_256x.png</PackageIconFullPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Identity" /> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" /> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.