views:

139

answers:

2

Hi Guys,

I host a wcf workflow service within my ASP.NET MVC2 application. I need to be able to load/save data inside my workflow (WF4). How it can be done? Should I just instantiate my Entity Framework context within my activities and read/write?

Cheers.

+1  A: 

There are several ways you can go about getting your data. You can use something like the WF ADO.NET Activity Pack CTP 1 from CodePlex, it works but can't say I am a fan. You can do something similar using EF, NHibernate ect in a CodeActivity. But in general I always tell people to split the what from the how. The workflow should be concerned with the what part and you should keep the how outside of the workflow itself. That would mean create a real simple activity that works with a workflow extension and put you data access code in the workflow extension. Once you do this your workflow extension is just another data repository and you can use standard coding techniques there.

Maurice
Yes, I completely agree with you and I'm also a big fan of separation of concern! Of course I have my data repositories.But instantiating my data repository service within WF activity is, in the end, instantiating my EF context.My question was: it it OK or should I create some kind of "external" service and register it somewhere in WF Runtime (as I supposed to do in WF3.5, as I understand).My question is more technical, and then I can make my decomposition on top :)What are the WF Extensions you mentioned?
Patrol02
A Wf4 extension is the same thing as a WF3 runtime service. You add it to the WorkflowInvoker/WorkflowApplication Extensions collection (or the WorkflowServiceHost WorkflowExtensions collection) and get a reference to it using the context.GetExtension<T>().
Maurice
+1  A: 

There is also the sample Entity Framework Activity pack in the WF 4.0 shipped samples.

Tim Lovell-Smith