C
C#6mo ago
Spaxter

Method on DI service doesn't do anything

Hello, I have a .NET app using Dependency Injection. One of the services I am injecting is a service for handling database insertions etc. Right now I have two methods on this class, one of them works perfectly fine but the other doesn't do anything when called. This is the method:
public async Task ClearGames()
{
_logger.LogDebug("ClearGames called");
using (var context = await _dbContextFactory.CreateDbContextAsync())
{
_logger.LogDebug("Truncating games table...");
try
{
await context.TruncateAsync<DbGame>();
await context.SaveChangesAsync();
} catch (Exception e)
{
_logger.LogError("{error}", e);
throw;
}
_logger.LogDebug("Truncate finished");
}
}
public async Task ClearGames()
{
_logger.LogDebug("ClearGames called");
using (var context = await _dbContextFactory.CreateDbContextAsync())
{
_logger.LogDebug("Truncating games table...");
try
{
await context.TruncateAsync<DbGame>();
await context.SaveChangesAsync();
} catch (Exception e)
{
_logger.LogError("{error}", e);
throw;
}
_logger.LogDebug("Truncate finished");
}
}
And when calling them like this, I only see the debug logs from the second method. The first one doesn't seem to run at all despite being called
await _db.ClearGames();
await _db.InsertGames(games);
await _db.ClearGames();
await _db.InsertGames(games);
8 Replies
Arvid
Arvid6mo ago
Try not using ' using'
kurumi
kurumi6mo ago
how you register _db?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX6mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
kurumi
kurumi6mo ago
what's wrong with blazor DI?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server