Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit fc019f0

Browse files
committed
WIP
1 parent f07d0b7 commit fc019f0

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/Shiny.Extensions.EntityFramework/EntityFrameworkExtensions.cs

+24-24
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ public static DbContextOptionsBuilder UseAuditing(this DbContextOptionsBuilder b
3030
}
3131

3232

33-
public static IServiceCollection AddDbContextQueryLogging<T>(this IServiceCollection services, TimeSpan minLogDuration) where T : class, IContextInfoProvider
34-
{
35-
services.AddScoped<T>();
36-
services.AddScoped(sp =>
37-
{
38-
var contextInfo = sp.GetRequiredService<T>();
39-
return new QueryLogDbCommandInterceptor(contextInfo, minLogDuration);
40-
});
41-
return services;
42-
}
43-
44-
45-
public static IServiceCollection AddDbContextQueryLogging(
46-
this IServiceCollection services,
47-
IContextInfoProvider contextProvider,
48-
TimeSpan minLogDuration
49-
) => services.AddScoped(_ => new QueryLogDbCommandInterceptor(contextProvider, minLogDuration));
50-
51-
52-
public static void UseQueryLogging(this DbContextOptionsBuilder builder, IServiceProvider scope)
53-
{
54-
var interceptor = scope.GetRequiredService<QueryLogDbCommandInterceptor>();
55-
builder.AddInterceptors(interceptor);
56-
}
33+
// public static IServiceCollection AddDbContextQueryLogging<T>(this IServiceCollection services, TimeSpan minLogDuration) where T : class, IContextInfoProvider
34+
// {
35+
// services.AddScoped<T>();
36+
// services.AddScoped(sp =>
37+
// {
38+
// var contextInfo = sp.GetRequiredService<T>();
39+
// return new QueryLogDbCommandInterceptor(contextInfo, minLogDuration);
40+
// });
41+
// return services;
42+
// }
43+
//
44+
//
45+
// public static IServiceCollection AddDbContextQueryLogging(
46+
// this IServiceCollection services,
47+
// IContextInfoProvider contextProvider,
48+
// TimeSpan minLogDuration
49+
// ) => services.AddScoped(_ => new QueryLogDbCommandInterceptor(contextProvider, minLogDuration));
50+
//
51+
//
52+
// public static void UseQueryLogging(this DbContextOptionsBuilder builder, IServiceProvider scope)
53+
// {
54+
// var interceptor = scope.GetRequiredService<QueryLogDbCommandInterceptor>();
55+
// builder.AddInterceptors(interceptor);
56+
// }
5757

5858

5959
public static ModelConfigurationBuilder SetDefaultStringLength(this ModelConfigurationBuilder configurationBuilder, int length = 50, bool unicode = true)

src/Shiny.Extensions.EntityFramework/QueryLog/QueryLogDbCommandInterceptor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected void TryLog(DbCommand command, CommandExecutedEventData eventData)
4343
};
4444
try
4545
{
46+
// TODO: may cause a loop due to nonexecutequery
4647
// TODO: cannot audit seeding/migrations data
4748
eventData.Context!.Add(log);
4849
eventData.Context.SaveChanges();

tests/Shiny.Extensions.EntityFramework.Tests/EfTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public EfTests()
1616

1717
var services = new ServiceCollection();
1818
services.AddDbContextAuditing(this.contextProvider);
19-
services.AddDbContextQueryLogging(this.contextProvider, TimeSpan.Zero);
19+
// services.AddDbContextQueryLogging(this.contextProvider, TimeSpan.Zero);
2020

2121
services.AddDbContext<TestDbContext>((sp, opts) => opts
2222
.UseNpgsql(new NpgsqlDataSourceBuilder("User ID=sa;Password=Blargh911!;Host=localhost;Port=5432;Database=AuditUnitTests;Pooling=true;Connection Lifetime=30;").Build())
2323
.UseAuditing(sp)
24-
.UseQueryLogging(sp)
24+
// .UseQueryLogging(sp)
2525
// .UseSqlite("Data Source=test.db")
2626
);
2727
this.serviceProvider = services.BuildServiceProvider();

0 commit comments

Comments
 (0)