Skip to content

Commit

Permalink
feat(ES.FX): add Microsoft.EntityFrameworkCore.SqlServer project and …
Browse files Browse the repository at this point in the history
…update dependencies

- Added new ES.FX.Microsoft.EntityFrameworkCore.SqlServer project to the solution.
- Updated OpenTelemetry.Instrumentation.AspNetCore, Http, and Runtime packages from version 1.8.1 to 1.9.0 in ES.FX.Ignite.Hosting.
- Replaced hardcoded "live" string with constant in IgniteHostingExtensions.cs and added HealthChecksTags class in ES.FX.Ignite.Spark.
- Created TestContainerDesignTimeFactory class for DbContext design time factory using MsSql Testcontainers in ES.FX.Microsoft.EntityFrameworkCore.SqlServer.
- Refactored SimpleDbContextDesignTimeFactory and TestDbContextDesignTimeFactory classes to inherit from TestContainerDesignTimeFactory.
- Updated Testcontainers.MsSql package from version 3.8.0 to 3.9.0 in ES.FX.Shared.SqlServer.Tests.

BREAKING CHANGE: This commit introduces significant changes that may affect existing functionality, including the addition of a new project and updates to several dependencies across multiple projects.
  • Loading branch information
winromulus committed Jun 18, 2024
1 parent 8f38d33 commit 33b05d7
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 63 deletions.
7 changes: 7 additions & 0 deletions ES.FX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ES.FX.Ignite.Seq", "src\ES.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ES.FX.Microsoft.Extensions.Diagnostics.HealthChecks", "src\ES.FX.Microsoft.Extensions.Diagnostics.HealthChecks\ES.FX.Microsoft.Extensions.Diagnostics.HealthChecks.csproj", "{6859E590-8534-41DE-B684-DE44C3A7061E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ES.FX.Microsoft.EntityFrameworkCore.SqlServer", "src\ES.FX.Microsoft.EntityFrameworkCore.SqlServer\ES.FX.Microsoft.EntityFrameworkCore.SqlServer.csproj", "{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -198,6 +200,10 @@ Global
{6859E590-8534-41DE-B684-DE44C3A7061E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6859E590-8534-41DE-B684-DE44C3A7061E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6859E590-8534-41DE-B684-DE44C3A7061E}.Release|Any CPU.Build.0 = Release|Any CPU
{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -236,6 +242,7 @@ Global
{BC9B5CA3-54F0-4194-8056-45729087FDC3} = {F8538BCE-36D3-4317-8C3C-7540117B99A7}
{1E500003-0805-485E-879E-2186FF6C7972} = {5A5969AF-86CB-489B-B0DE-C0BAADF5B424}
{6859E590-8534-41DE-B684-DE44C3A7061E} = {F8538BCE-36D3-4317-8C3C-7540117B99A7}
{9CFA0CB8-0E85-47DC-8C94-9D77CBC0A315} = {F8538BCE-36D3-4317-8C3C-7540117B99A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {388473D0-FE20-4821-BFE4-C3CD3E184C8F}
Expand Down
3 changes: 0 additions & 3 deletions playground/Playground.Microservice.Api.Host/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
"SqlServerClient": {
"SimpleDbContext": {
"ConnectionString": "Data Source=(local);Initial Catalog=SimpleDbContext;User ID=sa;Password=SuperPass#;MultipleActiveResultSets=true;Connect Timeout=1000;TrustServerCertificate=True"
},
"SimpleDbContext2": {
"ConnectionString": "Data Source=(local);Initial Catalog=SimpleDbContext;User ID=sa;Password=SuperPass#;MultipleActiveResultSets=true;Connect Timeout=1000;TrustServerCertificate=True"
}
},
"DbContext": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\ES.FX.Microsoft.EntityFrameworkCore.SqlServer\ES.FX.Microsoft.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\Playground.Shared.Data.Simple.EntityFrameworkCore\Playground.Shared.Data.Simple.EntityFrameworkCore.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
using JetBrains.Annotations;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer;

[PublicAPI]
public class SimpleDbContextDesignTimeFactory : IDesignTimeDbContextFactory<SimpleDbContext>
public class SimpleDbContextDesignTimeFactory : TestContainerDesignTimeFactory<SimpleDbContext>
{
public SimpleDbContext CreateDbContext(string[] args)
protected override void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder)
{
var optionsBuilder = new DbContextOptionsBuilder<SimpleDbContext>();
var sqlBuilder = new SqlConnectionStringBuilder
{
DataSource = "(local)",
UserID = "sa",
Password = "SuperPass#",
InitialCatalog = $"{nameof(SimpleDbContext)}_Design",
TrustServerCertificate = true
};
optionsBuilder.UseSqlServer(sqlBuilder.ConnectionString,
sqlServerDbContextOptionsBuilder =>
{
sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(SimpleDbContextDesignTimeFactory).Assembly
.FullName);
});

return new SimpleDbContext(optionsBuilder.Options);
base.ConfigureSqlServerOptions(builder);
builder.MigrationsAssembly(GetType().Assembly.FullName);
}
}
6 changes: 3 additions & 3 deletions src/ES.FX.Ignite.Hosting/ES.FX.Ignite.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.6.0" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions src/ES.FX.Ignite.Hosting/IgniteHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ES.FX.Ignite.Hosting.Configuration;
using ES.FX.Ignite.Spark;
using ES.FX.Ignite.Spark.Configuration;
using ES.FX.Ignite.Spark.HealthChecks;
using HealthChecks.ApplicationStatus.DependencyInjection;
using HealthChecks.UI.Client;
using JetBrains.Annotations;
Expand Down Expand Up @@ -89,7 +90,7 @@ private static void AddHealthChecks(IHostApplicationBuilder builder, IgniteHealt
{
var healthCheckKey = builder.Environment.ApplicationName;
var healthCheckBuilder = builder.Services.AddHealthChecks();
healthCheckBuilder.AddApplicationStatus(healthCheckKey, tags: ["live", nameof(Host)]);
healthCheckBuilder.AddApplicationStatus(healthCheckKey, tags: [HealthChecksTags.Live, nameof(Host)]);
}

private static void AddHttpClient(IHostApplicationBuilder builder, IgniteHttpClientSettings settings)
Expand Down Expand Up @@ -128,7 +129,7 @@ private static void UseHealthChecks(IHost host, IgniteHealthChecksSettings setti
//Only health checks tagged with the "live" tag must pass for app to be considered alive
var livenessHealthCheckOptions = new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
Predicate = r => r.Tags.Contains(HealthChecksTags.Live)
};
app.MapHealthChecks(settings.LivenessEndpointPath, livenessHealthCheckOptions);

Expand Down
9 changes: 9 additions & 0 deletions src/ES.FX.Ignite.Spark/HealthChecks/HealthChecksTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ES.FX.Ignite.Spark.HealthChecks;

public static class HealthChecksTags
{
/// <summary>
/// Tag used for liveness health checks
/// </summary>
public const string Live = "live";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.DependencyInjection;
using Testcontainers.MsSql;

namespace ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime;

/// <summary>
/// DbContext design time factory using MsSql Testcontainers
/// </summary>
/// <typeparam name="TDbContext"> The <see cref="TDbContext" /> to create</typeparam>
public class TestContainerDesignTimeFactory<TDbContext> : IDesignTimeDbContextFactory<TDbContext>
where TDbContext : DbContext
{
private MsSqlContainer? _container;

public TDbContext CreateDbContext(string[] args)
{
var builder = new MsSqlBuilder().WithName($"{GetType().Name}");
ConfigureMsSqlContainerBuilder(builder);
_container = builder.Build();

_container.StartAsync().Wait();
var optionsBuilder = new DbContextOptionsBuilder<TDbContext>();
optionsBuilder.UseSqlServer(_container.GetConnectionString(), ConfigureSqlServerOptions);


#pragma warning disable EF1001
var context = new DbContextFactorySource<TDbContext>().Factory(new ServiceCollection().BuildServiceProvider(),
optionsBuilder.Options);
#pragma warning restore EF1001

return context;
}

/// <summary>
/// Configures the SqlServerDbContextOptionsBuilder before the DbContext is created
/// </summary>
protected virtual void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder)
{
}

/// <summary>
/// Configures the MsSqlBuilder before the container is created
/// </summary>
protected virtual void ConfigureMsSqlContainerBuilder(MsSqlBuilder builder)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ES.FX.Microsoft.EntityFrameworkCore\ES.FX.Microsoft.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
using ES.FX.Ignite.Microsoft.EntityFrameworkCore.Tests.Context;
using ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime;
using JetBrains.Annotations;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace ES.FX.Ignite.Microsoft.EntityFrameworkCore.SqlServer.Tests.Context;

[PublicAPI]
public class TestDbContextDesignTimeFactory : IDesignTimeDbContextFactory<TestDbContext>
public class TestDbContextDesignTimeFactory : TestContainerDesignTimeFactory<TestDbContext>
{
public TestDbContext CreateDbContext(string[] args)
protected override void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder)
{
var optionsBuilder = new DbContextOptionsBuilder<TestDbContext>();
var sqlBuilder = new SqlConnectionStringBuilder
{
DataSource = "(local)",
UserID = "sa",
Password = "SuperPass#",
InitialCatalog = $"{nameof(TestDbContext)}_Design",
TrustServerCertificate = true
};
optionsBuilder.UseSqlServer(sqlBuilder.ConnectionString,
sqlServerDbContextOptionsBuilder =>
{
sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(TestDbContextDesignTimeFactory).Assembly
.FullName);
});

return new TestDbContext(optionsBuilder.Options);
base.ConfigureSqlServerOptions(builder);
builder.MigrationsAssembly(GetType().Assembly.FullName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\ES.FX.Ignite.Microsoft.EntityFrameworkCore.SqlServer\ES.FX.Ignite.Microsoft.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\..\src\ES.FX.Microsoft.EntityFrameworkCore.SqlServer\ES.FX.Microsoft.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\ES.FX.Ignite.Microsoft.EntityFrameworkCore.Tests\ES.FX.Ignite.Microsoft.EntityFrameworkCore.Tests.csproj" />
<ProjectReference Include="..\ES.FX.Shared.SqlServer.Tests\ES.FX.Shared.SqlServer.Tests.csproj" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Testcontainers.MsSql" Version="3.8.0" />
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 33b05d7

Please sign in to comment.