Subscriptions with Multiple Endpoint Instances - Instance has no subscribers

Hi, I have two Endpoints running in a single Process. Both monitor different SQS Queues (Say Q1 and Q2)
One message handler publishes an event at the end of the handler method. This message is sent to Q1.
The subscribers send their subscribe messages to Q1.
However the Endpoint that monitors Q2 is processing the subscription messages. It is also the Endpoint that is processing messages SENT to Q1.

I am using SQS transport. I am also using Autofac containers where I send in my .net core services collection and use

endpointConfiguration.UseContainer(customizations: customizations =>

Where the externalContainer is created using all services registered in my aspnet api application via an IServiceCollection extension.

public static IServiceCollection AddNSB(this IServiceCollection services, string hostName)

  //Build our container with all services required by the Handlers
  services.AddSingleton<IContainer>(_ =>
    var builder = new ContainerBuilder();
    return builder.Build();

This has been done so that the message handler can access services that are also used by the application.

I assume that something is getting registered in the container and the second endpoint is over-riding a service registered by the first Endpoint. This can be seen if I reverse the start sequence so that Q2 starts before Q1.
If I don’t use the services collection but instead explicitly register the services used by the message handlers then it works. However I would like to be able to use the same service collection provided by aspnet core.

Do you have any suggestions?

The problems are directly related to hosting the endpoints within the same process, rather than try and isolate the 2 endpoints via weird code configurations, why not simply host the endpoints in separate processes?

Sometimes just writing the problem down helps!
I’ve resolved this. I forgot the fundamental requirement for each endpoint instance to have it’s own container.
I removed the IOC registration for IContainer that I had above and created a new autofac container, using the passed in services collection. I now create a new container each time just before creating the endpoint.