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

Update Pomelo MySQL to v9 Preview #6948

Draft
wants to merge 1 commit 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
5 changes: 2 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
<PackageVersion Include="Milvus.Client" Version="2.3.0-preview.1" />
<PackageVersion Include="MongoDB.Driver" Version="[2.30.0,3.0.0)" />
<PackageVersion Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.5.0" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.3.6" />
<PackageVersion Include="MySqlConnector.Logging.Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.4.0" />
<PackageVersion Include="NATS.Net" Version="2.5.3" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="8.0.6" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLPackageVersion)" />
Expand All @@ -123,7 +122,7 @@
<PackageVersion Include="Oracle.ManagedDataAccess.OpenTelemetry" Version="23.6.0" />
<PackageVersion Include="Polly.Core" Version="8.5.0" />
<PackageVersion Include="Polly.Extensions" Version="8.5.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.2.efcore.9.0.0" />
<PackageVersion Include="Qdrant.Client" Version="1.12.0" />
<PackageVersion Include="RabbitMQ.Client" Version="[6.8.1,7.0.0)" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.22" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand All @@ -20,9 +20,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageReference Include="MySqlConnector.Logging.Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" VersionOverride="9.0.0" />
<PackageReference Include="MySqlConnector.DependencyInjection" />
<PackageReference Include="Polly.Extensions" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using Aspire;
using Aspire.Pomelo.EntityFrameworkCore.MySql;
Expand All @@ -10,7 +11,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MySqlConnector;
using MySqlConnector.Logging;
using Polly;
using Polly.Registry;
using Polly.Retry;
Expand Down Expand Up @@ -68,6 +68,7 @@ public static partial class AspireEFMySqlExtensions

configureSettings?.Invoke(settings);

builder.Services.AddMySqlDataSource(settings.ConnectionString ?? string.Empty);
builder.Services.AddDbContextPool<TContext>(ConfigureDbContext);

const string resilienceKey = "Microsoft.Extensions.Hosting.AspireEFMySqlExtensions.ServerVersion";
Expand All @@ -90,29 +91,21 @@ public static partial class AspireEFMySqlExtensions

void ConfigureDbContext(IServiceProvider serviceProvider, DbContextOptionsBuilder dbContextOptionsBuilder)
{
// use the legacy method of setting the ILoggerFactory because Pomelo EF Core doesn't use MySqlDataSource
if (serviceProvider.GetService<ILoggerFactory>() is { } loggerFactory)
{
MySqlConnectorLogManager.Provider = new MicrosoftExtensionsLoggingLoggerProvider(loggerFactory);
}

var connectionString = settings.ConnectionString ?? string.Empty;

ServerVersion serverVersion;
if (settings.ServerVersion is null)
{
ConnectionStringValidation.ValidateConnectionString(settings.ConnectionString, connectionName, DefaultConfigSectionName, $"{DefaultConfigSectionName}:{typeof(TContext).Name}", isEfDesignTime: EF.IsDesignTime);

var resiliencePipelineProvider = serviceProvider.GetRequiredService<ResiliencePipelineProvider<string>>();
var resiliencePipeline = resiliencePipelineProvider.GetPipeline(resilienceKey);
serverVersion = resiliencePipeline.Execute(static cs => ServerVersion.AutoDetect(cs), connectionString);
serverVersion = resiliencePipeline.Execute(static cs => ServerVersion.AutoDetect(cs), settings.ConnectionString);
}
else
{
serverVersion = ServerVersion.Parse(settings.ServerVersion);
}

var builder = dbContextOptionsBuilder.UseMySql(connectionString, serverVersion, builder =>
var builder = dbContextOptionsBuilder.UseMySql(serviceProvider.GetRequiredService<DbDataSource>(), serverVersion, builder =>
{
// delay validating the ConnectionString until the DbContext is configured. This ensures an exception doesn't happen until a Logger is established.
ConnectionStringValidation.ValidateConnectionString(settings.ConnectionString, connectionName, DefaultConfigSectionName, $"{DefaultConfigSectionName}:{typeof(TContext).Name}", isEfDesignTime: EF.IsDesignTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
<ProjectReference Include="..\..\src\Components\Aspire.Pomelo.EntityFrameworkCore.MySql\Aspire.Pomelo.EntityFrameworkCore.MySql.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" VersionOverride="9.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand All @@ -20,4 +20,13 @@
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" VersionOverride="9.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using MySqlConnector.Logging;
using OpenTelemetry.Trace;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure.Internal;
using Xunit;
Expand All @@ -31,12 +30,6 @@ protected override void RegisterComponent(HostApplicationBuilder builder, Action
{
builder.Services.AddDbContextPool<TestDbContext>((serviceProvider, options) =>
{
// use the legacy method of setting the ILoggerFactory because Pomelo EF Core doesn't use MySqlDataSource
if (serviceProvider.GetService<ILoggerFactory>() is { } loggerFactory)
{
MySqlConnectorLogManager.Provider = new MicrosoftExtensionsLoggingLoggerProvider(loggerFactory);
}

options.UseMySql(ConnectionString, DefaultVersion);
});
builder.EnrichMySqlDbContext<TestDbContext>(configure);
Expand Down
Loading