I'd like to create a set of custom activities that do work on a shared resource (like a file). These custom activities will be used in a number of workflows, each of which will have this shared resource in common. My goal is to make creating these workflows as simple as possible since each is just a rearrangement of a few basic activities.
I've managed to use an InArgument and pass this resource to each activity but since this is tedious I was wondering how I might simplify it so that the argument wouldn't be necessary.
Also, would it be possible to initialize this resource in one place so that all workflows could assume it already exists?
You can explore the use of Workflow Extensions if you like. Basically you leverage the "Service Locator" pattern.
Define a class that knows how to access/modify this file that you have. Say this class called ResourceLocator implements a IResourceLocator interface. Then when you create your workflow host do this
class ServiceLocator:IServiceLocator
{
public FileStream GetFile(string path){
}
}
//initiate WF host here host.Extensions.Add(()=>{new ResourceLocator();});
Then from within your custom activities you can do
context.GetExtension<IResourceLocator>().GetFile(pathToFile);
Basically this Extension becomes your means to share common code between workflows. You can split it out in a different assembly and share it between different workflow projects.