diff --git a/ECM.JobRunner.sln b/ECM.JobRunner.sln
index 520533d..979ff4c 100644
--- a/ECM.JobRunner.sln
+++ b/ECM.JobRunner.sln
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECMJobRunner.Infrastructure
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECMJobRunner.Application", "ECMJobRunner.Application\ECMJobRunner.Application.csproj", "{D97CD489-10D7-432C-9921-196F2E0505FF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECMJobRunner.Tests", "ECMJobRunner.Tests\ECMJobRunner.Tests.csproj", "{F64352B6-32BB-4BDE-90FD-FB77482D44E0}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
{D97CD489-10D7-432C-9921-196F2E0505FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D97CD489-10D7-432C-9921-196F2E0505FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D97CD489-10D7-432C-9921-196F2E0505FF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F64352B6-32BB-4BDE-90FD-FB77482D44E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F64352B6-32BB-4BDE-90FD-FB77482D44E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F64352B6-32BB-4BDE-90FD-FB77482D44E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F64352B6-32BB-4BDE-90FD-FB77482D44E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/ECMJobRunner.Infrastructure/DependencyExtension.cs b/ECMJobRunner.Infrastructure/DependencyExtension.cs
index 2084571..2a432f3 100644
--- a/ECMJobRunner.Infrastructure/DependencyExtension.cs
+++ b/ECMJobRunner.Infrastructure/DependencyExtension.cs
@@ -1,5 +1,6 @@
#if NET48
using System.Data.Entity;
+using Microsoft.Extensions.DependencyInjection;
#else
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@@ -10,7 +11,6 @@ using ECMJobRunner.Infrastructure.Repositories;
namespace ECMJobRunner.Infrastructure
{
-#if !NET48
///
/// Dependency injection extension methods for Infrastructure layer
///
@@ -24,11 +24,20 @@ namespace ECMJobRunner.Infrastructure
/// Service collection for chaining
public static IServiceCollection AddInfrastructure(this IServiceCollection services, string connectionString)
{
- // Register DbContext
+#if NET48
+ // Register DbContext as scoped for EF6 - same pattern as EF Core
+ // Each scope (request) gets its own DbContext instance
+ services.AddScoped(provider => new JobRunnerDbContext(connectionString));
+#else
+ // Register DbContext as scoped for EF Core
services.AddDbContext(options =>
options.UseSqlServer(connectionString));
+#endif
- // Register repositories
+ // Register AutoMapper
+ services.AddAutoMapper(typeof(DependencyExtension).Assembly);
+
+ // Register repositories as scoped (same lifetime as DbContext)
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped();
services.AddScoped();
@@ -37,5 +46,4 @@ namespace ECMJobRunner.Infrastructure
return services;
}
}
-#endif
}
diff --git a/ECMJobRunner.Infrastructure/ECMJobRunner.Infrastructure.csproj b/ECMJobRunner.Infrastructure/ECMJobRunner.Infrastructure.csproj
index 499d6ef..3e70db8 100644
--- a/ECMJobRunner.Infrastructure/ECMJobRunner.Infrastructure.csproj
+++ b/ECMJobRunner.Infrastructure/ECMJobRunner.Infrastructure.csproj
@@ -22,6 +22,10 @@
+
+
+
+
@@ -29,7 +33,7 @@
-
+