When writing a custom IPipelineContributor
it isn't clear how to get a reference to the selected Handler. The purpose of the custom contributor is to dispose any handlers that implement IDisposable
once they have returned a result.
Given the following code sample:
public class DisposerPipelineContributor : IPipelineContributor
{
public void Initialize(IPipeline pipelineRunner)
{
pipelineRunner.Notify(MyMethod).After<KnownStages.IOperationExecution>();
}
PipelineContinuation MyMethod(ICommunicationContext arg)
{
return PipelineContinuation.Continue;
}
}
The ICommunicationContext
gives us access to OpenRasta's own type system and reveals the type of selected handler: [OpenRasta.TypeSystem.ReflectionBased.ReflectionBasedType] = {CLR Type: MySelectedHandler}
. However, it isn't clear how to get the instance of the handler that was actually used to satisfy the request.
Iain,
first tings first, if you want features such as disposing of objects, you should use your own IoC container, most of those frameworks implement that functionality.
We're going to add disposing to the contract we have with containers in the next major version, as it is now more or less ok to do this, it wasn't when we built 2.0.
If you want to call IDisposable on a handler yourself and you cannot switch to a full-fledged IoC container, you'll find the handler instance in ICommunicationContext.PipelineData.