pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

ObjectDisposedException when using IInstanceFactory & Autofac container is disposed #367

Open flookami opened 6 years ago

flookami commented 6 years ago

Hi,

I am using IInstanceFactory and it happens that my app is crashing when stopping

here is a test method to reproduce the problem

    [Fact]
    public async Task Should_Be_Able_To_Resolve_Client_From_InstanceFactory_With_Autofac()
    {
        /* Setup */
        var builder = new ContainerBuilder();
        builder.RegisterRawRabbit();
        using (var container = builder.Build())
        {
            var instanceFactory = container.Resolve<IInstanceFactory>();
            /* Test */
            var client = instanceFactory.Create();
        }
        Assert.True(true);
    }

the problem happens in InstanceFactory class, Dispose method

var diposer = _resolver.GetService<IResourceDisposer>();

at this stage, _resolver is already disposed, leading to the ObjectDisposedException issue

any thoughts ?

Regards, Michael