diff --git a/src/ReC.Application/Common/Interfaces/IRecDbContext.cs b/src/ReC.Application/Common/Interfaces/IRecDbContext.cs new file mode 100644 index 0000000..730d6f9 --- /dev/null +++ b/src/ReC.Application/Common/Interfaces/IRecDbContext.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using ReC.Domain.Entities; + +namespace ReC.Application.Common.Interfaces; + +public interface IRecDbContext +{ + public DbSet EndpointParams { get; } + + public DbSet Actions { get; } + + public DbSet OutRes { get; } + + public DbSet HeaderQueryResults { get; } + + public DbSet BodyQueryResults { get; } + + public Task SaveChangesAsync(CancellationToken cancel = default); +} \ No newline at end of file diff --git a/src/ReC.Infrastructure/DependencyInjection.cs b/src/ReC.Infrastructure/DependencyInjection.cs index e4d4404..6cb2e77 100644 --- a/src/ReC.Infrastructure/DependencyInjection.cs +++ b/src/ReC.Infrastructure/DependencyInjection.cs @@ -1,6 +1,7 @@ using DigitalData.Core.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using ReC.Application.Common.Interfaces; using ReC.Domain.Entities; namespace ReC.Infrastructure; @@ -16,7 +17,9 @@ public static class DependencyInjection if(configOpt.DbContextOptionsAction is null) throw new InvalidOperationException("DbContextOptionsAction must be configured."); - services.AddDbContext(configOpt.DbContextOptionsAction); + services.AddDbContext(configOpt.DbContextOptionsAction); + + services.AddScoped(provider => provider.GetRequiredService()); services.AddDbRepository(opt => opt.RegisterFromAssembly(typeof(RecAction).Assembly)); diff --git a/src/ReC.Infrastructure/ReC.Infrastructure.csproj b/src/ReC.Infrastructure/ReC.Infrastructure.csproj index 04ccbf3..08889f7 100644 --- a/src/ReC.Infrastructure/ReC.Infrastructure.csproj +++ b/src/ReC.Infrastructure/ReC.Infrastructure.csproj @@ -13,6 +13,7 @@ + diff --git a/src/ReC.Infrastructure/RecDbContext.cs b/src/ReC.Infrastructure/RecDbContext.cs index 0efee4c..4ee76e2 100644 --- a/src/ReC.Infrastructure/RecDbContext.cs +++ b/src/ReC.Infrastructure/RecDbContext.cs @@ -1,9 +1,10 @@ using Microsoft.EntityFrameworkCore; +using ReC.Application.Common.Interfaces; using ReC.Domain.Entities; namespace ReC.Infrastructure; -public class RecDbContext(DbContextOptions options) : DbContext(options) +public class RecDbContext(DbContextOptions options) : DbContext(options), IRecDbContext { public DbSet EndpointParams { get; set; }