From eab38f1e345d389cb4d9553b6a5cf028b48064aa Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 25 Nov 2025 15:20:09 +0100 Subject: [PATCH] Integrate EF Core with SQL Server and Infrastructure Added `Microsoft.EntityFrameworkCore` and `ReC.Infrastructure` namespaces to `Program.cs` to enable EF Core functionality and infrastructure services. Configured the database context with a connection string from the app's configuration and added error handling for missing connection strings. Updated `ReC.API.csproj` to include the `Microsoft.EntityFrameworkCore.SqlServer` NuGet package (v9.0.11) for SQL Server support. Added a project reference to `ReC.Infrastructure` to enable the API project to use the infrastructure layer. --- src/ReC.API/Program.cs | 12 ++++++++++++ src/ReC.API/ReC.API.csproj | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/ReC.API/Program.cs b/src/ReC.API/Program.cs index 48863a6..fd0091a 100644 --- a/src/ReC.API/Program.cs +++ b/src/ReC.API/Program.cs @@ -1,6 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using ReC.Infrastructure; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. +builder.Services.AddInfrastructureServices(options => +{ + options.ConfigureDbContext((dbContextOpt) => + { + var connectionString = builder.Configuration.GetConnectionString("Default") + ?? throw new InvalidOperationException("Connection string is not found."); + dbContextOpt.UseSqlServer(connectionString); + }); +}); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/src/ReC.API/ReC.API.csproj b/src/ReC.API/ReC.API.csproj index 5419ef0..9145bb5 100644 --- a/src/ReC.API/ReC.API.csproj +++ b/src/ReC.API/ReC.API.csproj @@ -7,7 +7,12 @@ + + + + +