In Windows Workflow Foundation, you have two different ways of adding runtime services to the Workflow Engine:
- Through code, by using the AddService() method of the WorkflowRuntime class
- Through the application configuration file, by adding an entry to the
The latter is possible not only for the default services built into WF, like the SqlWorkflowPersistenceService, but also for your own ones; you just have to make sure you specify the correct type.
You might have noticed that some of the service take extra parameters on the configuration file. For example, for the SqlWorkflowPersistenceService entry you can configure parameters like the ConnectionString, IsTransactional and so on.
What may not be so obvious is that you can do the same thing for your own services and it's very easy! All you have to do is provide a constructor to your service class that takes a NameValueCollection as an argument; this collection will then have any named parameters that were included in the configuration entry. So, to keep in mind:
- Add your service to the configuration entry; each parameter is added as an attribute in the corresponding
tag. For example:
- Add alternate constructor to your service class with a NameValueCollection argument
- Extract named parameters from the NameValueCollection as needed to initialize your runtime service.