-
Notifications
You must be signed in to change notification settings - Fork 463
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
Adds Aspire Oracle EntityFrameworkCore Database component. #1295
Changes from 2 commits
92a7922
0f2f3f8
12ee396
0f384e8
773b457
06d7a4c
4db7868
824ed28
91e0b7b
74a10a0
ae61db3
9ac8eab
e04cee1
8b84294
5d99c70
7c09cbd
9abcdd8
5f0b689
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace Aspire.Hosting.Tests.Oracle; | ||
|
||
[Collection("IntegrationServices")] | ||
public class OracleDatabaseFunctionalTests | ||
{ | ||
private readonly IntegrationServicesFixture _integrationServicesFixture; | ||
|
||
public OracleDatabaseFunctionalTests(IntegrationServicesFixture integrationServicesFixture) | ||
{ | ||
_integrationServicesFixture = integrationServicesFixture; | ||
} | ||
|
||
[LocalOnlyFact()] | ||
public async Task VerifyOracleDatabaseWorks() | ||
{ | ||
var testProgram = _integrationServicesFixture.TestProgram; | ||
var client = _integrationServicesFixture.HttpClient; | ||
|
||
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)); | ||
|
||
var response = await testProgram.IntegrationServiceABuilder!.HttpGetAsync(client, "http", "/oracledatabase/verify", cts.Token); | ||
|
||
Assert.True(response.IsSuccessStatusCode); | ||
eerhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||
// Licensed to the .NET Foundation under one or more agreements. | ||||||
// The .NET Foundation licenses this file to you under the MIT license. | ||||||
|
||||||
using Oracle.ManagedDataAccess.Client; | ||||||
|
||||||
public static class OracleDatabaseExtensions | ||||||
{ | ||||||
public static void MapOracleDatabaseApi(this WebApplication app) | ||||||
{ | ||||||
app.MapGet("/oracledatabase/verify", VerifyOracleDatabaseAsync); | ||||||
} | ||||||
|
||||||
private static async Task<IResult> VerifyOracleDatabaseAsync(OracleConnection connection) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be
Suggested change
And then using the EF Component you are adding in this PR. |
||||||
{ | ||||||
try | ||||||
{ | ||||||
await connection.OpenAsync(); | ||||||
|
||||||
var command = connection.CreateCommand(); | ||||||
command.CommandText = $"SELECT 1 FROM DUAL"; | ||||||
var results = await command.ExecuteReaderAsync(); | ||||||
|
||||||
return results.HasRows ? Results.Ok("Success!") : Results.Problem("Failed"); | ||||||
} | ||||||
catch (Exception e) | ||||||
{ | ||||||
return Results.Problem(e.ToString()); | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Oracle.ManagedDataAccess.Client; | ||
|
||
// This is a workaround while https://github.com/dotnet/aspire/pull/1004 is not merged. | ||
public static class OracleManagedDataAccessExtensions | ||
{ | ||
public static void AddOracleClient(this WebApplicationBuilder builder, string connectionName) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
var connectionString = builder.Configuration.GetConnectionString(connectionName); | ||
builder.Services.AddScoped(_ => new OracleConnection(connectionString)); | ||
} | ||
|
||
public static void AddKeyedOracleClient(this WebApplicationBuilder builder, string connectionName) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
var connectionString = builder.Configuration.GetConnectionString(connectionName); | ||
builder.Services.AddKeyedSingleton(connectionName, (serviceProvider, _) => new OracleConnection(connectionString)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,15 @@ | |
builder.AddNpgsqlDataSource("postgresdb"); | ||
builder.AddRabbitMQ("rabbitmqcontainer"); | ||
builder.AddMongoDBClient("mymongodb"); | ||
builder.AddOracleClient("freepdb1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test program should be using the Oracle EF Component you are adding, not a workaround method and talking to an OracleConnection directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. It makes perfect sense, I got a little lost here. Thank you for the explanation. |
||
|
||
builder.AddKeyedSqlServerClient("sqlserverabstract"); | ||
builder.AddKeyedMySqlDataSource("mysqlabstract"); | ||
builder.AddKeyedRedis("redisabstract"); | ||
builder.AddKeyedNpgsqlDataSource("postgresabstract"); | ||
builder.AddKeyedRabbitMQ("rabbitmqabstract"); | ||
builder.AddKeyedMongoDBClient("mongodbabstract"); | ||
builder.AddKeyedOracleClient("oracledatabaseabstract"); | ||
|
||
var app = builder.Build(); | ||
|
||
|
@@ -36,4 +38,6 @@ | |
|
||
app.MapRabbitMQApi(); | ||
|
||
app.MapOracleDatabaseApi(); | ||
|
||
app.Run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should centralize this generated password logic into
PasswordUtils
@mitchdennyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it is different than SqlServer.
aspire/src/Aspire.Hosting/SqlServer/SqlServerBuilderExtensions.cs
Line 25 in bc220e3
and MySql
aspire/src/Aspire.Hosting/MySql/MySqlBuilderExtensions.cs
Line 27 in bc220e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably just come up with a decent password generator that we can use. What I did for SQL Server was half baked and really only appropriate for inner loop (which luckily is where it is used). I'd be happy to see this go in without change this password generation logic and instead see an issue created where we properly develop out PasswordUtils than can meet our various use cases (needs to be flexible enough to side step various limitations around what the containerized tool can used, and what we can escape in the connection string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know an issue hasn't been created yet, but I saw this comment and opened a PR that might address it: #1469.