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

Enable ConfigurationBinder source gen on components by default #535

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageVersion Include="Azure.Identity" Version="1.10.0" />
<PackageVersion Include="Azure.Messaging.ServiceBus" Version="7.15.0" />
<PackageVersion Include="Azure.Messaging.EventHubs" Version="5.9.2" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed until Xabaril/AspNetCore.Diagnostics.HealthChecks#2038 is shipped in a version on nuget. The ServiceBus health check brings in EventHubs, and I needed to add an explicit alias to work around the source generator bug.

<PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.17.0" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.15.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageTags>$(ComponentAzurePackageTags) tables table</PackageTags>
<Description>A client for Azure Table Storage that integrates with Aspire, including health checks, logging, and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)AzureTable_256x.png</PackageIconFullPath>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,9 +15,11 @@

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Azure.Data.Tables" />
<PackageReference Include="Azure.Data.Tables" />
<!-- Aliases works around https://github.com/dotnet/runtime/issues/93498 -->
<PackageReference Include="Azure.Data.Tables" Aliases="AzureDataTables" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Azure" Aliases="ExtensionsAzure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// workaround https://github.com/dotnet/runtime/issues/93498
extern alias AzureDataTables;
extern alias ExtensionsAzure;
global using AzureDataTables.Azure.Data.Tables;
global using ExtensionsAzure.Microsoft.Extensions.Azure;

using Aspire.Azure.Common;
using Aspire.Azure.Data.Tables;
using Azure.Core;
using Azure.Core.Extensions;
using Azure.Data.Tables;
using HealthChecks.Azure.Data.Tables;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

Expand Down Expand Up @@ -76,6 +82,18 @@ protected override IAzureClientBuilder<TableServiceClient, TableClientOptions> A
}, requiresCredential: false);
}

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<TableServiceClient, TableClientOptions> clientBuilder, IConfiguration configuration)
{
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should just make IDE0200 a suggestion? This seems like a pretty aggressive warning.

clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
}

protected override void BindSettingsToConfiguration(AzureDataTablesSettings settings, IConfiguration configuration)
{
configuration.Bind(settings);
}

protected override IHealthCheck CreateHealthCheck(TableServiceClient client, AzureDataTablesSettings settings)
=> new AzureTableServiceHealthCheck(client, new AzureTableServiceHealthCheckOptions());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable IDE0161 // Convert to file-scoped namespace

// empty namespace declarations workaround https://github.com/dotnet/runtime/issues/93498
namespace Azure.Data.Tables { }
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageTags>$(ComponentAzurePackageTags) servicebus amqp</PackageTags>
<Description>A client for Azure Service Bus that integrates with Aspire, including health checks, logging and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)AzureServiceBus_256x.png</PackageIconFullPath>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,8 +16,11 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Messaging.ServiceBus" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<!-- Aliases works around https://github.com/dotnet/runtime/issues/93498 -->
<PackageReference Include="Azure.Messaging.EventHubs" Aliases="Unused" />
<PackageReference Include="Azure.Messaging.ServiceBus" Aliases="AzureMessagingServiceBus" />
<PackageReference Include="Microsoft.Extensions.Azure" Aliases="ExtensionsAzure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// workaround https://github.com/dotnet/runtime/issues/93498
extern alias AzureMessagingServiceBus;
extern alias ExtensionsAzure;
global using AzureMessagingServiceBus.Azure.Messaging.ServiceBus;
global using ExtensionsAzure.Microsoft.Extensions.Azure;

using Aspire.Azure.Common;
using Aspire.Azure.Messaging.ServiceBus;
using Azure.Core;
using Azure.Core.Extensions;
using Azure.Messaging.ServiceBus;
using HealthChecks.AzureServiceBus;
using HealthChecks.AzureServiceBus.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

Expand Down Expand Up @@ -93,6 +99,18 @@ protected override IHealthCheck CreateHealthCheck(ServiceBusClient client, Azure
Credential = settings.Credential
});

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<ServiceBusClient, ServiceBusClientOptions> clientBuilder, IConfiguration configuration)
{
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
}

protected override void BindSettingsToConfiguration(AzureMessagingServiceBusSettings settings, IConfiguration config)
{
config.Bind(settings);
}

protected override bool GetHealthCheckEnabled(AzureMessagingServiceBusSettings settings)
=> !string.IsNullOrEmpty(settings.HealthCheckQueueName) || !string.IsNullOrEmpty(settings.HealthCheckTopicName);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// empty namespace declarations workaround https://github.com/dotnet/runtime/issues/93498
namespace Azure.Messaging.ServiceBus { }
namespace Microsoft.Azure.Messaging.ServiceBus { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<!-- AOT-compat blocked by https://github.com/dotnet/runtime/issues/94071 -->
<EnableConfigurationBindingGenerator>false</EnableConfigurationBindingGenerator>
<IsAotCompatible>false</IsAotCompatible>
<PackageTags>$(ComponentAzurePackageTags) keyvault secrets</PackageTags>
<Description>A client for Azure Key Vault that integrates with Aspire, including health checks, logging and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)AzureKeyVault_256x.png</PackageIconFullPath>
Expand All @@ -18,6 +21,7 @@
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

global using Microsoft.Extensions.Azure;

using Aspire.Azure.Common;
using Aspire.Azure.Security.KeyVault;
using Azure.Core;
Expand Down Expand Up @@ -131,6 +133,18 @@ protected override IAzureClientBuilder<SecretClient, SecretClientOptions> AddCli
protected override IHealthCheck CreateHealthCheck(SecretClient client, AzureSecurityKeyVaultSettings settings)
=> new AzureKeyVaultSecretsHealthCheck(client, new AzureKeyVaultSecretOptions());

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<SecretClient, SecretClientOptions> clientBuilder, IConfiguration configuration)
{
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
}

protected override void BindSettingsToConfiguration(AzureSecurityKeyVaultSettings settings, IConfiguration configuration)
{
configuration.Bind(settings);
}

protected override bool GetHealthCheckEnabled(AzureSecurityKeyVaultSettings settings)
=> settings.HealthChecks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<!-- AOT-compat blocked by https://github.com/dotnet/runtime/issues/94071 -->
<EnableConfigurationBindingGenerator>false</EnableConfigurationBindingGenerator>
<IsAotCompatible>false</IsAotCompatible>
<PackageTags>$(ComponentAzurePackageTags) storage blobs blob</PackageTags>
<Description>A client for Azure Blob Storage that integrates with Aspire, including health checks, logging and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)AzureStorageContainer_256x.png</PackageIconFullPath>
Expand All @@ -17,6 +20,7 @@
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Storage.Blobs" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

global using Microsoft.Extensions.Azure;

using Aspire.Azure.Common;
using Aspire.Azure.Storage.Blobs;
using Azure.Core;
using Azure.Core.Extensions;
using Azure.Storage.Blobs;
using HealthChecks.Azure.Storage.Blobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

Expand Down Expand Up @@ -76,6 +79,18 @@ protected override IAzureClientBuilder<BlobServiceClient, BlobClientOptions> Add
}, requiresCredential: false);
}

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<BlobServiceClient, BlobClientOptions> clientBuilder, IConfiguration configuration)
{
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
}

protected override void BindSettingsToConfiguration(AzureStorageBlobsSettings settings, IConfiguration configuration)
{
configuration.Bind(settings);
}

protected override IHealthCheck CreateHealthCheck(BlobServiceClient client, AzureStorageBlobsSettings settings)
=> new AzureBlobStorageHealthCheck(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<!-- AOT-compat blocked by https://github.com/dotnet/runtime/issues/94071 -->
<EnableConfigurationBindingGenerator>false</EnableConfigurationBindingGenerator>
<IsAotCompatible>false</IsAotCompatible>
<PackageTags>$(ComponentAzurePackageTags) storage queue queues</PackageTags>
<Description>A client for Azure Queue Storage that integrates with Aspire, including health checks, logging and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)AzureStorageQueue_256x.png</PackageIconFullPath>
Expand All @@ -17,6 +20,7 @@
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Storage.Queues" />
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

global using Microsoft.Extensions.Azure;

using Aspire.Azure.Common;
using Aspire.Azure.Storage.Queues;
using Azure.Core;
using Azure.Core.Extensions;
using Azure.Storage.Queues;
using HealthChecks.Azure.Storage.Queues;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

Expand Down Expand Up @@ -76,6 +79,18 @@ protected override IAzureClientBuilder<QueueServiceClient, QueueClientOptions> A
}, requiresCredential: false);
}

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<QueueServiceClient, QueueClientOptions> clientBuilder, IConfiguration configuration)
{
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
}

protected override void BindSettingsToConfiguration(AzureStorageQueuesSettings settings, IConfiguration configuration)
{
configuration.Bind(settings);
}

protected override IHealthCheck CreateHealthCheck(QueueServiceClient client, AzureStorageQueuesSettings settings)
=> new AzureQueueStorageHealthCheck(client, new AzureQueueStorageHealthCheckOptions());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<IsAotCompatible>true</IsAotCompatible>
<PackageTags>$(ComponentDatabasePackageTags) sqlserver sql</PackageTags>
<Description>A Microsoft SQL Server client that integrates with Aspire, including health checks, metrics and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)SQL_256x.png</PackageIconFullPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" />
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.EventCounters" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Data.SqlClient" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<IsAotCompatible>true</IsAotCompatible>
<PackageTags>$(ComponentEfCorePackageTags) sqlserver sql</PackageTags>
<Description>A Microsoft SQL Server provider for Entity Framework Core that integrates with Aspire, including connection pooling, health check, logging, and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)SQL_256x.png</PackageIconFullPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.EventCounters" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<IsAotCompatible>true</IsAotCompatible>
<PackageTags>$(ComponentEfCorePackageTags) postgressql postgres npgsql sql</PackageTags>
<Description>A PostgreSQL® provider for Entity Framework Core that integrates with Aspire, including connection pooling, health checks, logging, and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)PostgreSQL_logo.3colors.540x557.png</PackageIconFullPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Npgsql.DependencyInjection" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Npgsql.OpenTelemetry" />
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Aspire.Npgsql/Aspire.Npgsql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<IsAotCompatible>true</IsAotCompatible>
<PackageTags>$(ComponentDatabasePackageTags) postgressql postgres npgsql sql</PackageTags>
<Description>A PostgreSQL® client that integrates with Aspire, including health checks, metrics, logging, and telemetry.</Description>
Expand Down
Loading
Loading