Skip to content

Commit 02b6241

Browse files
committed
updated services, entities, database, canvas schema
1 parent 55bb0a3 commit 02b6241

File tree

27 files changed

+345
-178
lines changed

27 files changed

+345
-178
lines changed

Database/src/ThingsLibrary.Database.SqlServer/Extensions/Database.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// </copyright>
66
// ================================================================================
77

8+
using ThingsLibrary.Services.Extensions;
9+
810
namespace ThingsLibrary.Database.SqlServer.Extensions
911
{
1012
public static class DatabaseExtensions
@@ -22,7 +24,21 @@ public static IServiceCollection AddDatabaseSqlServer<TContext>(this IServiceCol
2224
ArgumentNullException.ThrowIfNullOrEmpty(parameterName);
2325

2426
var connectionString = configuration.TryGetConnectionString(parameterName);
25-
27+
28+
services.AddDatabaseSqlServer<TContext>(connectionString);
29+
30+
return services;
31+
}
32+
33+
/// <summary>
34+
/// Add SQL Server Database
35+
/// </summary>
36+
/// <param name="services">Service Collection</param>
37+
/// <param name="connectionString">Connection String</param>
38+
/// <returns></returns>
39+
/// <exception cref="ArgumentException"></exception>
40+
public static IServiceCollection AddDatabaseSqlServer<TContext>(this IServiceCollection services, string connectionString) where TContext : Database.DataContext
41+
{
2642
// verify a SQL connection can be established before continuing
2743
using (var connection = new SqlConnection(connectionString))
2844
{

Database/src/ThingsLibrary.Database.SqlServer/ThingsLibrary.Database.SqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>true</IsPackable>

Database/src/ThingsLibrary.Database.SqlServer/Usings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@
3030
// ================================================================================
3131
// LOCAL
3232
// ================================================================================
33-
global using ThingsLibrary.Services.Extensions;

Database/src/ThingsLibrary.Database/DataContext.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,13 @@ public static void LogDatabaseSettings(ILogger logger, DbConnectionStringBuilder
198198
// Postgres
199199

200200
}
201-
}
201+
202+
/// <summary>
203+
/// Do any database prechecks and data seeding
204+
/// </summary>
205+
public virtual void Prechecks()
206+
{
207+
this.Database.EnsureCreated();
208+
}
209+
}
202210
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ================================================================================
2+
// <copyright file="DatabaseHealthCheck.cs" company="Starlight Software Co">
3+
// Copyright (c) Starlight Software Co. All rights reserved.
4+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
5+
// </copyright>
6+
// ================================================================================
7+
8+
using Microsoft.Extensions.Diagnostics.HealthChecks;
9+
10+
namespace ThingsLibrary.Database.HealthChecks
11+
{
12+
/// <summary>
13+
/// Configuration Variables: HealthCheck.Database.Response
14+
/// </summary>
15+
public class ContactServiceHealthCheck : IHealthCheck
16+
{
17+
private DbContext DataContext { get; set; }
18+
19+
/// <summary>
20+
/// Constructor
21+
/// </summary>
22+
/// <param name="context">Data Context</param>
23+
public ContactServiceHealthCheck(DbContext context)
24+
{
25+
this.DataContext = context;
26+
}
27+
28+
/// <summary>
29+
/// Check the health
30+
/// </summary>
31+
/// <param name="context">Health Check Context</param>
32+
/// <param name="cancellationToken">Cancel Token</param>
33+
/// <returns>Health Status</returns>
34+
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
35+
{
36+
try
37+
{
38+
// Perform a simple query to check database connectivity
39+
if (!await this.DataContext.Database.CanConnectAsync(cancellationToken))
40+
{
41+
return HealthCheckResult.Unhealthy("Database is not reachable.");
42+
}
43+
44+
return HealthCheckResult.Healthy("Database is reachable.");
45+
}
46+
catch (Exception ex)
47+
{
48+
return HealthCheckResult.Unhealthy("Database check failed.", ex);
49+
}
50+
}
51+
}
52+
}

Database/src/ThingsLibrary.Database/ThingsLibrary.Database.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>true</IsPackable>
@@ -25,11 +25,10 @@
2525
<ItemGroup>
2626
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
2727
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.6" />
28-
<PackageReference Include="Serilog" Version="4.3.0" />
28+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="9.0.6" />
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<ProjectReference Include="..\..\..\Base\src\ThingsLibrary.Base\ThingsLibrary.csproj" />
3332
<ProjectReference Include="..\..\..\Services\src\ThingsLibrary.Services\ThingsLibrary.Services.csproj" />
3433
</ItemGroup>
3534

Entity/src/ThingsLibrary.Entity.Mongo/Extensions/ServiceCollection.cs renamed to Entity/src/ThingsLibrary.Entity.Mongo/Extensions/IServiceCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ================================================================================
2-
// <copyright file="ServiceCollection.cs" company="Starlight Software Co">
2+
// <copyright file="IServiceCollection.cs" company="Starlight Software Co">
33
// Copyright (c) Starlight Software Co. All rights reserved.
44
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
55
// </copyright>

Entity/src/ThingsLibrary.Entity/DataContext.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,13 @@ public void CreateIndexes<T>(EntityTypeBuilder<T> builder) where T : class
7373
// builder.HasIndex(indexAttribute.PropertyNames.ToArray());
7474
//}
7575
}
76-
77-
#region --- Seed Base Data ---
78-
76+
7977
/// <summary>
8078
/// Do any database prechecks and data seeding
8179
/// </summary>
8280
public virtual void Prechecks()
8381
{
8482
this.Database.EnsureCreated();
85-
}
86-
87-
#endregion
88-
83+
}
8984
}
9085
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ================================================================================
2+
// <copyright file="DatabaseHealthCheck.cs" company="Starlight Software Co">
3+
// Copyright (c) Starlight Software Co. All rights reserved.
4+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
5+
// </copyright>
6+
// ================================================================================
7+
8+
using Microsoft.Extensions.Diagnostics.HealthChecks;
9+
10+
namespace ThingsLibrary.Entity.HealthChecks
11+
{
12+
/// <summary>
13+
/// Configuration Variables: HealthCheck.Database.Response
14+
/// </summary>
15+
public class DatabaseHealthCheck : IHealthCheck
16+
{
17+
private DbContext DataContext { get; set; }
18+
19+
/// <summary>
20+
/// Constructor
21+
/// </summary>
22+
/// <param name="context">Data Context</param>
23+
public DatabaseHealthCheck(DbContext context)
24+
{
25+
this.DataContext = context;
26+
}
27+
28+
/// <summary>
29+
/// Check the health
30+
/// </summary>
31+
/// <param name="context">Health Check Context</param>
32+
/// <param name="cancellationToken">Cancel Token</param>
33+
/// <returns>Health Status</returns>
34+
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
35+
{
36+
try
37+
{
38+
// Perform a simple query to check database connectivity
39+
if (!await this.DataContext.Database.CanConnectAsync(cancellationToken))
40+
{
41+
return HealthCheckResult.Unhealthy("Database is not reachable.");
42+
}
43+
44+
45+
return HealthCheckResult.Healthy("Database is reachable.");
46+
}
47+
catch (Exception ex)
48+
{
49+
return HealthCheckResult.Unhealthy("Database check failed.", ex);
50+
}
51+
}
52+
}
53+
}

Entity/src/ThingsLibrary.Entity/ThingsLibrary.Entity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
2424
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.6" />
25+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="9.0.6" />
2526
</ItemGroup>
2627

2728
<ItemGroup>

0 commit comments

Comments
 (0)