Is it OK to use IUnityContainer as an extension in workflow activities (WF 4.0)?
protected override bool Execute(CodeActivityContext context)
{
var container = context.GetExtension<IUnityContainer>();
var db = container.Resolve<IDatabaseContext>();
// ...
}
Please, give me an example how to do it right.
I’d refrain from having the container be placed in the extension list. Just get the extensions you really need, IDatabaseContext in your case. Less is usually better.
Regarding the best approach to including a dependency injection framework, one way would be to wrap a WorkflowApplication or WorkflowInvoker object in a utility class that supports Unity, and providing all the interfaces/types as extensions to the internal WorkflowApplication.
One other recommendation is register the required extensions in your activity’s CacheMetadata method. This method is used in validating the workflow prior to its execution.