Senpawaii
Senpawaii
CC#
Created by Senpawaii on 6/5/2023 in #help
✅ Weird values on accessing Database using EF DbContext under throughput load test
Ok, I think I get it! Thanks 😄
12 replies
CC#
Created by Senpawaii on 6/5/2023 in #help
✅ Weird values on accessing Database using EF DbContext under throughput load test
I should add that all the queries return the expected values (both under load and not under load).
12 replies
CC#
Created by Senpawaii on 5/26/2023 in #help
❔ Visual Studio 2022 - Debugging error on trying to launch Performance Profiler
If any needed info is missing, I can post it here
3 replies
CC#
Created by Senpawaii on 3/28/2023 in #help
❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]
And finally the implementation of AddCustomDbContext, called on the previous code block.
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration)
{
services.AddEntityFrameworkSqlServer()
.AddDbContext<CatalogContext>(options => {
options.UseSqlServer( ... );
});

});
return services;
}
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration)
{
services.AddEntityFrameworkSqlServer()
.AddDbContext<CatalogContext>(options => {
options.UseSqlServer( ... );
});

});
return services;
}
5 replies
CC#
Created by Senpawaii on 3/28/2023 in #help
❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]
How I configure my Services and dependencies (using Autofac):
public Startup(IConfiguration configuration) {
Configuration = configuration;
}

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddHttpContextAccessor()
.AddCustomDbContext(Configuration)
[ ... ]

var container = new ContainerBuilder();
container.Populate(services);

return new AutofacServiceProvider(container.Build());
}
public Startup(IConfiguration configuration) {
Configuration = configuration;
}

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddHttpContextAccessor()
.AddCustomDbContext(Configuration)
[ ... ]

var container = new ContainerBuilder();
container.Populate(services);

return new AutofacServiceProvider(container.Build());
}
5 replies
CC#
Created by Senpawaii on 3/28/2023 in #help
❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]
The implementation of the custom DbContext class, where the Interceptor is added:
public class CatalogContext : DbContext
{
public CatalogContext(DbContextOptions<CatalogContext> options, IHttpContextAccessor httpContextAccessor) : base(options)
{
_httpContextAccessor = httpContextAccessor;
}
private readonly IHttpContextAccessor _httpContextAccessor;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.AddInterceptors(new DemoInterceptor(_httpContextAccessor));
}
}
public class CatalogContext : DbContext
{
public CatalogContext(DbContextOptions<CatalogContext> options, IHttpContextAccessor httpContextAccessor) : base(options)
{
_httpContextAccessor = httpContextAccessor;
}
private readonly IHttpContextAccessor _httpContextAccessor;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.AddInterceptors(new DemoInterceptor(_httpContextAccessor));
}
}
5 replies