© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
19 replies
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);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ api doesn't return anything.
C#CC# / help
3y ago
❔ Bool method that doesn't work
C#CC# / help
3y ago
DI Service Usage in Quartz.NET registration
C#CC# / help
13mo ago
❔ Method WriteToTable(); isn't doing anything to the database file
C#CC# / help
4y ago