0
votes

Here goes - bear with me:

Two Autofac 4.2.1 Containers:

  • One in an Asp.NET 4.6.1 WebApi project
  • One in an NServiceBus 6 host

Both possess an IJobService reference to the JobService (which saves jobs to DynamoDB).

Run the project in Visual Studio...

If I make a WebApi request into the first JobService it succeeds and inserts a record to DynamoDB and drops a command on the bus for NServiceBus to pickup.

During the processing of the Saga, NServiceBus makes a call to JobService again (presumably on the second container) to save progress. This second call fails to insert to DynamoDB with the lifetime disposed. If I try to create anything from IComponentContext I get:

Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

The NServiceBus host is running AsA_Server and I register the container in the Customize method of IConfigureThisEndPoint.

Any pointers on how to see where the lifetime is getting dumped or if it's mysteriously picking the wrong IJobService somehow?

1
How do you register JobService on both container ? Could you share your registration configuration ? - Cyril Durand
I dug into it a bit more and it looks like the entire Child Container is getting disposed halfway through the work under the Saga Handler... I'm not seeing anything in the logs and the critical failure isn't being triggered (which is a common cause of the container going poof unexpected). I'll dig some more and see if I can't get some nugget of information to provide better assistance. - Bryce Ashey

1 Answers

0
votes

Just to close this one out - we ended up redesigning the solution and moving any web service calls out to their own handlers. That was based off the advice found here http://docs.particular.net/nservicebus/sagas That change resolved the issue one way or another.

Specifically, this guidance:

Other than interacting with its own internal state, a saga should not access a database, call out to web services, or access other resources - neither directly nor indirectly by having such dependencies injected into it.