Skip to content

Commit c29aa41

Browse files
🐛 Bug fixes
1 parent 9f4ba58 commit c29aa41

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/AppHost/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
// Note: To run without Docker, simply remove sql and database:
44
// builder.AddProject<Projects.Web>("web");
55

6+
#if (!UseSqlite)
67
var sql = builder.AddSqlServer("sql");
78

89
var database = sql.AddDatabase("CleanArchitectureDb");
910

1011
builder.AddProject<Projects.Web>("web")
1112
.WaitFor(database)
1213
.WithReference(database);
14+
#else
15+
builder.AddProject<Projects.Web>("web");
16+
#endif
1317

1418
builder.Build().Run();

src/Infrastructure/DependencyInjection.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,30 @@ public static class DependencyInjection
1515
{
1616
public static void AddInfrastructureServices(this IHostApplicationBuilder builder)
1717
{
18-
builder.Services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>();
19-
builder.Services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>();
20-
2118
var connectionString = builder.Configuration.GetConnectionString("CleanArchitectureDb");
2219
Guard.Against.Null(connectionString, message: "Connection string 'CleanArchitectureDb' not found.");
23-
24-
#if (UseSqlite)
20+
21+
builder.Services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>();
22+
builder.Services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>();
23+
24+
#if (UseSqlite)
2525
builder.Services.AddDbContext<ApplicationDbContext>((sp, options) =>
2626
{
2727
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
2828
options.UseSqlite(connectionString);
29-
});
30-
#else
31-
#if (UseAspire)
32-
builder.AddSqlServerDbContext<ApplicationDbContext>("CleanArchitectureDb", null, options =>
33-
{
34-
var sp = builder.Services.BuildServiceProvider();
35-
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
36-
});
37-
#else
29+
});
30+
#else
3831
builder.Services.AddDbContext<ApplicationDbContext>((sp, options) =>
3932
{
4033
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
4134
options.UseSqlServer(connectionString);
4235
});
43-
#endif
44-
#endif
36+
#if (UseAspire)
4537

38+
builder.EnrichSqlServerDbContext<ApplicationDbContext>();
39+
#endif
40+
#endif
41+
4642
builder.Services.AddScoped<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>());
4743

4844
builder.Services.AddScoped<ApplicationDbContextInitialiser>();

tests/Application.FunctionalTests/CustomWebApplicationFactory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,27 @@ public CustomWebApplicationFactory(DbConnection connection)
2424

2525
protected override void ConfigureWebHost(IWebHostBuilder builder)
2626
{
27+
#if (UseAspire)
28+
builder.UseSetting("ConnectionStrings:CleanArchitectureDb", _connection.ConnectionString);
29+
#endif
2730
builder.ConfigureTestServices(services =>
2831
{
2932
services
3033
.RemoveAll<IUser>()
3134
.AddTransient(provider => Mock.Of<IUser>(s => s.Id == GetUserId()));
32-
35+
#if (!UseAspire || UseSqlite)
3336
services
3437
.RemoveAll<DbContextOptions<ApplicationDbContext>>()
3538
.AddDbContext<ApplicationDbContext>((sp, options) =>
3639
{
3740
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
38-
#if (UseSqlite)
41+
#if (UseSqlite)
3942
options.UseSqlite(_connection);
40-
#else
43+
#else
4144
options.UseSqlServer(_connection);
42-
#endif
45+
#endif
4346
});
47+
#endif
4448
});
4549
}
4650
}

0 commit comments

Comments
 (0)