I have WebAPI project in which I have created a ControllerActivator which uses an custom dependency scope that essentially calls the StructureMap container.GetNestedContainer() in order to create a nested container per request.
I then have a custom controller activator which uses this nested container (via the custom dependency scope) to activate my controllers. All of the dependencies are injected by StructureMap into the controllers, and all of the dependencies of the dependencies are inject, and so on.
I have an authenticator (action filter) which runs prior to the controller activator and uses the IContainer.Inject() method to inject an identity into the nested container for each individual request. If I set a break point in the controller activator where I ask the container for the specific controller that I'm going to activate, I can do:
_container.GetInstance(typeof(IMyIdentity))
And the dependency scope's container (this would be the nested container) returns me the instance that I expect it to. However, when I press F10 to let it attempt to resolve the controller I get the error:
No default Instance is registered and cannot be automatically determined for type 'IMyIdentity'
This comes with a list of about 6 chained dependencies that it was trying to create to fulfill the requirements of the controller it was trying to create. For the life of me I can't figure out why I can ask the container directly for the instance and it will give it to me, but when it's asked indirectly it can't find it. Also a _container.WhatDoIHave() shows the MyIdentity class being registered to the IMyIdentity interface with a name of "(Default)" and a lifecycle of "Object" (althought I'm not sure what "Object" lifecycle means).