Dependency Injection with Windows Workflow Foundation 4 advanced

In this follow up post I try to tackle the more advanced stuff which is possible with the new ninject extension for Windows Workflow Foundation. The goal is to show the following topics:

  • Hooking into the injection chain
  • Possible side effects
  • Changing the extensions behavior
  • Download the extension

How to hook into the injection chain?

In some cases you want to perform additional stuff on the activities. For example register certain activities on an Event Broker etc.
This can be achieved by implementing IActivityInjectorExtension. With CanProcess the extension must indicate whether it likes to
process a certain activity or not. In the Process method the actual operation such as registering on event broker etc. can be done.


The extensions are collected upon creation of the IActivityInjector. The order of the extension invocation is not predictable.

Possible side effects?

The default activity resolver uses WorkflowInspectionServices.GetActivities recursively to retrieve all activities under a certain root activity.
This can have the following side effects (extract from MSDN):

To retrieve a specific activity instead of enumerating all of the activities,
Resolve is used. Both Resolve and GetActivities perform metadata caching if
WorkflowInspectionServices.CacheMetadata has not been previously called.
If CacheMetadata has been called then GetActivities is based on the existing metadata.
Therefore, if tree changes have been made since the last call to CacheMetadata,
GetActivities might give unexpected results. If changes have been made to the workflow
after calling GetActivities, metadata can be re-cached by calling the ActivityValidationServices Validate
method. Caching metadata is discussed in the next section.

You know it better?

If you have a smarter idea how to resolve all activities then you can swap out the internals of the extension. Simply rebind IActivityResolver.


Where can I download this exciting extension?



About the author

Daniel Marbach

Add comment

By Daniel Marbach

Recent Posts