Skip to content
Open
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
9 changes: 4 additions & 5 deletions Connectors/src/MySql/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Data.Common;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using MySqlConnector;
using Steeltoe.Connectors;
using Steeltoe.Connectors.MySql;
using Steeltoe.Samples.MySql.Models;

namespace Steeltoe.Samples.MySql.Controllers;

public sealed class HomeController(ConnectorFactory<MySqlOptions, MySqlConnection> connector) : Controller
public sealed class HomeController(ConnectorFactory<MySqlOptions, MySqlConnectionAlias> connector) : Controller
{
private readonly Connector<MySqlOptions, MySqlConnection> _connector = connector.Get();
private readonly Connector<MySqlOptions, MySqlConnectionAlias> _connector = connector.Get();

public async Task<IActionResult> Index(CancellationToken cancellationToken)
{
Expand All @@ -20,9 +19,9 @@ public async Task<IActionResult> Index(CancellationToken cancellationToken)
ConnectionString = _connector.Options.ConnectionString
};

await using MySqlConnection connection = _connector.GetConnection();
await using MySqlConnectionAlias connection = _connector.GetConnection();
await connection.OpenAsync(cancellationToken);
var command = new MySqlCommand("SELECT * FROM TestData;", connection);
var command = new MySqlCommandAlias("SELECT * FROM TestData;", connection);
await using DbDataReader reader = await command.ExecuteReaderAsync(cancellationToken);

while (await reader.ReadAsync(cancellationToken))
Expand Down
17 changes: 8 additions & 9 deletions Connectors/src/MySql/MySqlSeeder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using MySqlConnector;
using Steeltoe.Connectors;
using Steeltoe.Connectors.MySql;

Expand All @@ -8,30 +7,30 @@ internal sealed class MySqlSeeder
{
public static async Task CreateSampleDataAsync(IServiceProvider serviceProvider)
{
var connectorFactory = serviceProvider.GetRequiredService<ConnectorFactory<MySqlOptions, MySqlConnection>>();
await using MySqlConnection connection = connectorFactory.Get().GetConnection();
var connectorFactory = serviceProvider.GetRequiredService<ConnectorFactory<MySqlOptions, MySqlConnectionAlias>>();
await using MySqlConnectionAlias connection = connectorFactory.Get().GetConnection();

await connection.OpenAsync();

await DropCreateTableAsync(connection);
await InsertSampleDataAsync(connection);
}

private static async Task DropCreateTableAsync(MySqlConnection connection)
private static async Task DropCreateTableAsync(MySqlConnectionAlias connection)
{
var dropCommand = new MySqlCommand("DROP TABLE IF EXISTS TestData;", connection);
var dropCommand = new MySqlCommandAlias("DROP TABLE IF EXISTS TestData;", connection);
await dropCommand.ExecuteNonQueryAsync();

var createCommand = new MySqlCommand("CREATE TABLE IF NOT EXISTS TestData(Id INT PRIMARY KEY, MyText VARCHAR(255));", connection);
var createCommand = new MySqlCommandAlias("CREATE TABLE IF NOT EXISTS TestData(Id INT PRIMARY KEY, MyText VARCHAR(255));", connection);
await createCommand.ExecuteNonQueryAsync();
}

private static async Task InsertSampleDataAsync(MySqlConnection connection)
private static async Task InsertSampleDataAsync(MySqlConnectionAlias connection)
{
var insertCommand1 = new MySqlCommand("INSERT INTO TestData(Id, MyText) VALUES(1, 'Row1 Text');", connection);
var insertCommand1 = new MySqlCommandAlias("INSERT INTO TestData(Id, MyText) VALUES(1, 'Row1 Text');", connection);
await insertCommand1.ExecuteNonQueryAsync();

var insertCommand2 = new MySqlCommand("INSERT INTO TestData(Id, MyText) VALUES(2, 'Row2 Text');", connection);
var insertCommand2 = new MySqlCommandAlias("INSERT INTO TestData(Id, MyText) VALUES(2, 'Row2 Text');", connection);
await insertCommand2.ExecuteNonQueryAsync();
}
}
3 changes: 1 addition & 2 deletions Connectors/src/MySql/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using MySqlConnector;
using Steeltoe.Configuration.CloudFoundry;
using Steeltoe.Connectors.MySql;
using Steeltoe.Management.Endpoint.Actuators.All;
Expand All @@ -21,7 +20,7 @@
// Steeltoe: optionally change the MySQL connection string at runtime.
builder.Services.Configure<MySqlOptions>(options =>
{
var connectionStringBuilder = new MySqlConnectionStringBuilder
var connectionStringBuilder = new MySqlConnectionStringBuilderAlias
{
ConnectionString = options.ConnectionString,
UseCompression = false
Expand Down
17 changes: 11 additions & 6 deletions Connectors/src/MySql/Steeltoe.Samples.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseOraclePackage>false</UseOraclePackage>
</PropertyGroup>

<ItemGroup>
<!-- Either one of these MySQL NuGet packages should work in this sample. -->
<PackageReference Include="MySqlConnector" Version="2.5.*" />
<!--
<PackageReference Include="MySql.Data" Version="9.7.*" />
-->

<PackageReference Include="MySql.Data" Condition="'$(UseOraclePackage)' == 'true'" Version="9.7.*" />
<PackageReference Include="MySqlConnector" Condition="'$(UseOraclePackage)' != 'true'" Version="2.6.*" />
<PackageReference Include="Steeltoe.Connectors" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.Endpoint" Version="$(SteeltoeVersion)" />
</ItemGroup>

<ItemGroup>
<Using Condition="'$(UseOraclePackage)' == 'true'" Alias="MySqlConnectionAlias" Include="MySql.Data.MySqlClient.MySqlConnection" />
<Using Condition="'$(UseOraclePackage)' != 'true'" Alias="MySqlConnectionAlias" Include="MySqlConnector.MySqlConnection" />
<Using Condition="'$(UseOraclePackage)' == 'true'" Alias="MySqlCommandAlias" Include="MySql.Data.MySqlClient.MySqlCommand" />
<Using Condition="'$(UseOraclePackage)' != 'true'" Alias="MySqlCommandAlias" Include="MySqlConnector.MySqlCommand" />
<Using Condition="'$(UseOraclePackage)' == 'true'" Alias="MySqlConnectionStringBuilderAlias" Include="MySql.Data.MySqlClient.MySqlConnectionStringBuilder" />
<Using Condition="'$(UseOraclePackage)' != 'true'" Alias="MySqlConnectionStringBuilderAlias" Include="MySqlConnector.MySqlConnectionStringBuilder" />
</ItemGroup>
</Project>
7 changes: 3 additions & 4 deletions Connectors/src/MySqlEFCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using MySql.EntityFrameworkCore.Infrastructure;
using Steeltoe.Configuration.CloudFoundry;
using Steeltoe.Connectors.EntityFrameworkCore.MySql;
using Steeltoe.Connectors.MySql;
Expand Down Expand Up @@ -36,13 +35,13 @@
// Steeltoe: Setup DbContext connection strings, optionally changing MySQL options at runtime.
builder.Services.AddDbContext<AppDbContext>((serviceProvider, options) => options.UseMySql(serviceProvider, serviceOneName, null, untypedOptions =>
{
var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions;
var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions;
mySqlOptions.CommandTimeout(20);
}));

builder.Services.AddDbContext<OtherDbContext>((serviceProvider, options) => options.UseMySql(serviceProvider, serviceTwoName, null, untypedOptions =>
{
var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions;
var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions;
mySqlOptions.CommandTimeout(25);
}));
}
Expand All @@ -54,7 +53,7 @@
// Steeltoe: Setup DbContext connection string, optionally changing MySQL options at runtime.
builder.Services.AddDbContext<AppDbContext>((serviceProvider, options) => options.UseMySql(serviceProvider, null, null, untypedOptions =>
{
var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions;
var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions;
mySqlOptions.CommandTimeout(15);
}));
}
Expand Down
16 changes: 10 additions & 6 deletions Connectors/src/MySqlEFCore/Steeltoe.Samples.MySqlEFCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseOraclePackage>false</UseOraclePackage>
</PropertyGroup>

<ItemGroup>
<!-- Either one of these MySQL EF Core NuGet packages should work in this sample. -->
<PackageReference Include="MySql.EntityFrameworkCore" Version="10.0.*" />
<!--
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EFCoreVersion)" />
-->

<PackageReference Include="Microting.EntityFrameworkCore.MySql" Condition="'$(UseOraclePackage)' != 'true'" Version="$(EFCoreVersion)" />
<PackageReference Include="MySql.EntityFrameworkCore" Condition="'$(UseOraclePackage)' == 'true'" Version="$(EFCoreVersion)" />
<PackageReference Include="Steeltoe.Connectors.EntityFrameworkCore" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.Endpoint" Version="$(SteeltoeVersion)" />
</ItemGroup>

<ItemGroup>
<Using Condition="'$(UseOraclePackage)' == 'true'" Alias="MySqlDbContextOptionsBuilderAlias"
Include="MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder" />
<Using Condition="'$(UseOraclePackage)' != 'true'" Alias="MySqlDbContextOptionsBuilderAlias"
Include="Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions Management/src/ActuatorApi/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<AspNetCoreVersion>10.0.*</AspNetCoreVersion>
<EFCoreVersion>
<!-- Temporary workaround: EF Core 10 package for Pomelo.EntityFrameworkCore.MySql is not available yet. -->
9.0.*
</EFCoreVersion>
<EFCoreVersion>10.0.*</EFCoreVersion>
<OpenTelemetryVersion>1.15.*</OpenTelemetryVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microting.EntityFrameworkCore.MySql" Version="$(EFCoreVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Extensions.Propagators" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EFCoreVersion)" />
<PackageReference Include="Steeltoe.Connectors.EntityFrameworkCore" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.GitProperties.Build" Version="$(SteeltoeVersion)" />
<PackageReference Include="Steeltoe.Management.Prometheus" Version="$(SteeltoeVersion)" />
Expand Down