Skip to content

Commit 058756a

Browse files
authored
Throw error if ICurrentUserService isn't registered before database call (#43)
1 parent 31e7482 commit 058756a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Libraries/Infrastructure/DatabaseExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public static class DatabaseExtensions
1414
{
1515
public static IHostApplicationBuilder AddDatabaseServices(this IHostApplicationBuilder builder)
1616
{
17+
if (!builder.Services.Any(x => x.ServiceType == typeof(ICurrentUserService)))
18+
{
19+
throw new InvalidOperationException(
20+
"ICurrentUserService must be registered before calling AddDatabaseServices. " +
21+
"Register an implementation using builder.Services.AddScoped<ICurrentUserService, YourImplementation>()");
22+
}
23+
1724
builder.Services.AddScoped<AuditSaveChangesInterceptor>();
1825

1926
builder.Services.AddDbContext<AuditContext>((sp, options) =>

0 commit comments

Comments
 (0)