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.
This commit is contained in:
2025-11-25 15:20:09 +01:00
parent e552658d2e
commit eab38f1e34
2 changed files with 17 additions and 0 deletions

View File

@@ -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