C#C
C#2y 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");
        }
    }


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);
Was this page helpful?