CleanArchitecture.WorkerService icon indicating copy to clipboard operation
CleanArchitecture.WorkerService copied to clipboard

{"Cannot access a disposed object.\r\nObject name: 'IServiceProvider'."} after multiple runs

Open aligneddev opened this issue 5 years ago • 1 comments

I added the ServiceLocator in #3. I've now found that when I run the service for multiple loops, we get {"Cannot access a disposed object.\r\nObject name: 'IServiceProvider'."}.

aligneddev avatar Dec 06 '19 20:12 aligneddev

I'm unable to reproduce with this unit test, I only get it at run time. Here was my attempt at a test.

    [Fact]
    public async Task MessageWasRetrievedFromTheQueue_WorksManyTimes()
    {
        // simulate multiple runs
        // avoid {"Cannot access a disposed object.\r\nObject name: 'IServiceProvider'."}
        var (service, _, _, _, _) = Factory();
        await service.ExecuteAsync();
        await service.ExecuteAsync();
        await service.ExecuteAsync();
        await service.ExecuteAsync();
        var (service2, _, _, _, _) = Factory();
        await service2.ExecuteAsync();
        var (service3, _, _, _, _) = Factory();
        await service3.ExecuteAsync();

        Assert.True(true);
    }

aligneddev avatar Dec 06 '19 20:12 aligneddev

Should be fixed now I hope.

ardalis avatar Sep 16 '22 18:09 ardalis