Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspire Client Integrations util project #6999

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaprServiceC", "playground\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dashboard", "Dashboard", "{830F7CA9-8E51-4D62-832F-91F53F85B7AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Client", "src\Components\Aspire.Client\Aspire.Client.csproj", "{9551D5BD-F7A8-4537-98CC-56483F8A0A6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1653,6 +1655,10 @@ Global
{B26653B9-439E-4850-A7F8-43C6E5121952}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B26653B9-439E-4850-A7F8-43C6E5121952}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B26653B9-439E-4850-A7F8-43C6E5121952}.Release|Any CPU.Build.0 = Release|Any CPU
{9551D5BD-F7A8-4537-98CC-56483F8A0A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9551D5BD-F7A8-4537-98CC-56483F8A0A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9551D5BD-F7A8-4537-98CC-56483F8A0A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9551D5BD-F7A8-4537-98CC-56483F8A0A6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1956,6 +1962,7 @@ Global
{042DD8C6-A26C-4B06-80A1-FE7F8659C5BC} = {B7345F72-712F-436C-AE18-CAF7CDD4A990}
{B26653B9-439E-4850-A7F8-43C6E5121952} = {57A42144-739E-49A7-BADB-BB8F5F20FA17}
{830F7CA9-8E51-4D62-832F-91F53F85B7AE} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{9551D5BD-F7A8-4537-98CC-56483F8A0A6B} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -31,6 +29,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
<ProjectReference Include="..\Aspire.OpenAI\Aspire.OpenAI.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -29,4 +27,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -29,5 +27,9 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,5 +26,9 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -27,5 +25,9 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,4 +26,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -30,4 +28,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -29,4 +27,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -29,4 +27,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Components/Aspire.Client/Aspire.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>aspire</PackageTags>
<Description>A package containing utilities for building Aspire Client integrations.</Description>
<PackageIconFullPath>$(SharedDir)As-ire_icon_256.png</PackageIconFullPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
</ItemGroup>
</Project>
33 changes: 33 additions & 0 deletions src/Components/Aspire.Client/ConfigurationSchemaAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire;

/// <summary>
/// Attribute used to automatically generate a JSON schema for a component's configuration.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="ConfigurationSchemaAttribute"/> class.
/// </remarks>
/// <param name="path">The path corresponding to which config section <see cref="Type"/> binds to.</param>
/// <param name="type">The type that is bound to the configuration. This type will be walked and generate a JSON schema for all the properties.</param>
/// <param name="exclusionPaths">(optional) The config sections to exclude from the ConfigurationSchema. This is useful if there are properties you don't want to publicize in the config schema.</param>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class ConfigurationSchemaAttribute(string path, Type type, string[]? exclusionPaths = null) : Attribute
{

/// <summary>
/// The path corresponding to which config section <see cref="Type"/> binds to.
/// </summary>
public string Path { get; } = path;

/// <summary>
/// The type that is bound to the configuration. This type will be walked and generate a JSON schema for all the properties.
/// </summary>
public Type Type { get; } = type;

/// <summary>
/// (optional) The config sections to exclude from the ConfigurationSchema. This is useful if there are properties you don't want to publicize in the config schema.
/// </summary>
public string[]? ExclusionPaths { get; } = exclusionPaths;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@

namespace Aspire;

internal static class ConnectionStringValidation
/// <summary>
/// Provides a method to validate a connection string.
/// </summary>
public static class ConnectionStringValidation
{
/// <summary>
/// Validates the provided connection string.
/// </summary>
/// <param name="connectionString">The connection string to validate.</param>
/// <param name="connectionName">The name of the connection.</param>
/// <param name="defaultConfigSectionName">The default configuration section name.</param>
/// <param name="typeSpecificSectionName">The type-specific configuration section name (optional).</param>
/// <param name="isEfDesignTime">Indicates if it is EF design time (optional).</param>
/// <exception cref="InvalidOperationException">Thrown when the connection string is missing and it is not EF design time.</exception>
public static void ValidateConnectionString(string? connectionString, string connectionName, string defaultConfigSectionName, string? typeSpecificSectionName = null, bool isEfDesignTime = false)
{
if (string.IsNullOrWhiteSpace(connectionString) && !isEfDesignTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

namespace Aspire;

internal static class HealthChecksExtensions
/// <summary>
/// Provides extension methods for adding health checks to the IHostApplicationBuilder.
/// </summary>
public static class HealthChecksExtensions
{
/// <summary>
/// Adds a HealthCheckRegistration if one hasn't already been added to the builder.
/// </summary>
/// <param name="builder">The IHostApplicationBuilder to add the health check to.</param>
/// <param name="healthCheckRegistration">The HealthCheckRegistration to add.</param>
public static void TryAddHealthCheck(this IHostApplicationBuilder builder, HealthCheckRegistration healthCheckRegistration)
{
builder.TryAddHealthCheck(healthCheckRegistration.Name, hcBuilder => hcBuilder.Add(healthCheckRegistration));
Expand All @@ -20,6 +25,9 @@ public static void TryAddHealthCheck(this IHostApplicationBuilder builder, Healt
/// <summary>
/// Invokes the <paramref name="addHealthCheck"/> action if the given <paramref name="name"/> hasn't already been added to the builder.
/// </summary>
/// <param name="builder">The IHostApplicationBuilder to add the health check to.</param>
/// <param name="name">The name of the health check.</param>
/// <param name="addHealthCheck">The action to add the health check.</param>
public static void TryAddHealthCheck(this IHostApplicationBuilder builder, string name, Action<IHealthChecksBuilder> addHealthCheck)
{
var healthCheckKey = $"Aspire.HealthChecks.{name}";
Expand Down
21 changes: 21 additions & 0 deletions src/Components/Aspire.Client/LoggingCategoriesAttribute.cs
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.

namespace Aspire;

/// <summary>
/// Provides information to describe the logging categories produced by a component.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="LoggingCategoriesAttribute"/> class.
/// </remarks>
/// <param name="categories">The list of log categories produced by the component. These categories will show up under the Logging:LogLevel section in appsettings.json.</param>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class LoggingCategoriesAttribute(params string[] categories) : Attribute
{

/// <summary>
/// The list of log categories produced by the component. These categories will show up under the Logging:LogLevel section in appsettings.json.
/// </summary>
public string[] Categories { get; set; } = categories;
}
Empty file.
15 changes: 15 additions & 0 deletions src/Components/Aspire.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable
Aspire.ConfigurationSchemaAttribute
Aspire.ConfigurationSchemaAttribute.ConfigurationSchemaAttribute(string! path, System.Type! type, string![]? exclusionPaths = null) -> void
Aspire.ConfigurationSchemaAttribute.ExclusionPaths.get -> string![]?
Aspire.ConfigurationSchemaAttribute.Path.get -> string!
Aspire.ConfigurationSchemaAttribute.Type.get -> System.Type!
Aspire.ConnectionStringValidation
Aspire.HealthChecksExtensions
Aspire.LoggingCategoriesAttribute
Aspire.LoggingCategoriesAttribute.Categories.get -> string![]!
Aspire.LoggingCategoriesAttribute.Categories.set -> void
Aspire.LoggingCategoriesAttribute.LoggingCategoriesAttribute(params string![]! categories) -> void
static Aspire.ConnectionStringValidation.ValidateConnectionString(string? connectionString, string! connectionName, string! defaultConfigSectionName, string? typeSpecificSectionName = null, bool isEfDesignTime = false) -> void
static Aspire.HealthChecksExtensions.TryAddHealthCheck(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckRegistration! healthCheckRegistration) -> void
static Aspire.HealthChecksExtensions.TryAddHealthCheck(this Microsoft.Extensions.Hosting.IHostApplicationBuilder! builder, string! name, System.Action<Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder!>! addHealthCheck) -> void
9 changes: 9 additions & 0 deletions src/Components/Aspire.Client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Aspire.Client

Provides a set of common services and utilities for .NET Aspire Client integration packages.

This package provides no integration package-specific functionality.

## Feedback & contributing

https://github.com/dotnet/aspire
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<MinCodeCoverage>90</MinCodeCoverage>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Kafka" />
<PackageReference Include="Confluent.Kafka" />
Expand All @@ -24,4 +20,8 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<PropertyGroup>
<MinCodeCoverage>80</MinCodeCoverage>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" />
Expand All @@ -26,4 +21,8 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Client\Aspire.Client.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\..\Shared\Cosmos\CosmosConstants.cs" Link="Shared\CosmosConstants.cs" />
<Compile Include="..\..\Shared\Cosmos\CosmosUtils.cs" Link="Shared\CosmosUtils.cs" />
</ItemGroup>
Expand Down
Loading
Loading