Refactor DbContext configuration for flexibility
Updated `ConfigureDbContext` to accept `IServiceProvider`, enabling dependency injection during database context setup. Modified `DependencyInjection.cs` to align with this change by updating `DbContextOptionsAction` and its related method signature. Removed unused `System.IO` and `System.Text.Json` namespaces from `RecActionController.cs` to improve code cleanliness.
This commit is contained in:
parent
dc408e7794
commit
60e5adbf1a
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using ReC.API.Models;
|
using ReC.API.Models;
|
||||||
using ReC.Application.RecActions.Commands;
|
using ReC.Application.RecActions.Commands;
|
||||||
using ReC.Application.RecActions.Queries;
|
using ReC.Application.RecActions.Queries;
|
||||||
using System.IO;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace ReC.API.Controllers;
|
namespace ReC.API.Controllers;
|
||||||
|
|||||||
@ -16,7 +16,7 @@ builder.Services.AddRecServices(options =>
|
|||||||
|
|
||||||
builder.Services.AddRecInfrastructure(options =>
|
builder.Services.AddRecInfrastructure(options =>
|
||||||
{
|
{
|
||||||
options.ConfigureDbContext((dbContextOpt) =>
|
options.ConfigureDbContext((provider, dbContextOpt) =>
|
||||||
{
|
{
|
||||||
var connectionString = builder.Configuration.GetConnectionString("Default")
|
var connectionString = builder.Configuration.GetConnectionString("Default")
|
||||||
?? throw new InvalidOperationException("Connection string is not found.");
|
?? throw new InvalidOperationException("Connection string is not found.");
|
||||||
|
|||||||
@ -31,9 +31,9 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
public class ConfigurationOptions
|
public class ConfigurationOptions
|
||||||
{
|
{
|
||||||
internal Action<DbContextOptionsBuilder>? DbContextOptionsAction { get; private set; }
|
internal Action<IServiceProvider, DbContextOptionsBuilder>? DbContextOptionsAction { get; private set; }
|
||||||
|
|
||||||
public ConfigurationOptions ConfigureDbContext(Action<DbContextOptionsBuilder> optionsAction)
|
public ConfigurationOptions ConfigureDbContext(Action<IServiceProvider, DbContextOptionsBuilder> optionsAction)
|
||||||
{
|
{
|
||||||
DbContextOptionsAction = optionsAction;
|
DbContextOptionsAction = optionsAction;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user