Skip to content

Commit

Permalink
Create a base class for all ADO.NET databases
Browse files Browse the repository at this point in the history
This will allow use of all ADO.NET databases without need to reference
exact package for the ADO.NET component.

For example, EfCore will be able to use PostgreSQL and SQL Server
without need to depend on either package.
  • Loading branch information
jahav committed Sep 3, 2024
1 parent b2070f2 commit 12d324f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/DataIsland.Core/AdoNetDatabaseTenant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DataIsland;

/// <summary>
/// A base tenant for relational databases.
/// </summary>
/// <param name="ConnectionString">Connection string to the database.</param>
/// <param name="DatabaseName">Name of the database (unescaped).</param>
public abstract record AdoNetDatabaseTenant(string ConnectionString, string DatabaseName)
{
}
4 changes: 2 additions & 2 deletions src/DataIsland.EfCore/DataIsland.EfCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<!--<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />-->
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DataIsland.SqlServer\DataIsland.SqlServer.csproj" />
<ProjectReference Include="..\DataIsland.Core\DataIsland.Core.csproj" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/DataIsland.EfCore/EfCorePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using DataIsland.SqlServer;

namespace DataIsland.EfCore;

Expand Down Expand Up @@ -47,7 +46,7 @@ public void Register(IServiceCollection serviceCollection)
Func<IServiceProvider, object> newFactory = sp =>
{
var testContext = sp.GetRequiredService<ITestContext>();
var tenant = testContext.GetTenant<SqlDatabaseTenant>(typeof(TDbContext));
var tenant = testContext.GetTenant<AdoNetDatabaseTenant>(typeof(TDbContext));

var originalOptions = (DbContextOptions<TDbContext>)originalFactory(sp);
var relationalExtension = originalOptions.Extensions.OfType<RelationalOptionsExtension>().Single();
Expand Down
3 changes: 2 additions & 1 deletion src/DataIsland.SqlServer/SqlDatabaseTenant.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
namespace DataIsland.SqlServer;

public record SqlDatabaseTenant(string ConnectionString, SqlServerComponent Component, string DatabaseName);
public record SqlDatabaseTenant(string ConnectionString, SqlServerComponent Component, string DatabaseName)
: AdoNetDatabaseTenant(ConnectionString, DatabaseName);

0 comments on commit 12d324f

Please sign in to comment.