Compare commits

..

3 Commits

Author SHA1 Message Date
9847b6e6f7 Change assembly name constant spelling
Some checks are pending
continuous-integration/drone/push Build is running
2025-06-12 19:18:17 +02:00
ada0e2f665 Use custom activity source 2025-06-12 19:12:38 +02:00
b28bd2826b Keep db container after apps shutdown 2025-06-12 19:12:26 +02:00
4 changed files with 29 additions and 12 deletions

View File

@@ -2,6 +2,8 @@
using FluentValidation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using System.Diagnostics;
using System.Reflection;
using Vegasco.Server.Api.Authentication;
using Vegasco.Server.Api.Common;
using Vegasco.Server.Api.Persistence;
@@ -27,6 +29,14 @@ public static class DependencyInjectionExtensions
private static IServiceCollection AddMiscellaneousServices(this IServiceCollection services)
{
services.AddSingleton(sp =>
{
var assemblyName = Assembly.GetExecutingAssembly()
.GetName()
.Name ?? "Vegasco.Server.Api";
return new ActivitySource(assemblyName);
});
services.AddResponseCompression();
services.AddValidatorsFromAssemblies(

View File

@@ -1,18 +1,24 @@
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
namespace Vegasco.Server.Api.Persistence;
public class ApplyMigrationsService(ILogger<ApplyMigrationsService> logger, IServiceScopeFactory scopeFactory)
: IHostedService
public class ApplyMigrationsService(
ILogger<ApplyMigrationsService> logger,
IServiceScopeFactory scopeFactory,
ActivitySource activitySource)
: IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Starting migrations");
using IServiceScope scope = scopeFactory.CreateScope();
await using var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.MigrateAsync(cancellationToken);
}
public async Task StartAsync(CancellationToken cancellationToken)
{
using var activity = activitySource.StartActivity("ApplyMigrations");
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
logger.LogInformation("Starting migrations");
using IServiceScope scope = scopeFactory.CreateScope();
await using var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.MigrateAsync(cancellationToken);
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}

View File

@@ -4,7 +4,7 @@ public static class Constants
{
public static class Projects
{
public const string Api = "Vegasco_Server_Api";
public const string Api = "Vegasco.Server.Api";
}
public static class Database

View File

@@ -3,6 +3,7 @@ using Vegasco.Server.AppHost.Shared;
IDistributedApplicationBuilder builder = DistributedApplication.CreateBuilder(args);
IResourceBuilder<PostgresDatabaseResource> postgres = builder.AddPostgres(Constants.Database.ServiceName)
.WithLifetime(ContainerLifetime.Persistent)
.WithDataVolume()
.AddDatabase(Constants.Database.Name);