Using WF activities with Dependency Injection in a CAL application

Nov 17, 2008 at 6:21 PM
Most of the types we typically use from modules are loaded using the IOC mechanism in CAL e.g. JobsViewPresentationModel has a constructor
        public JobsViewPresentationModel(IJobsView view, IWorkflowController workflowController,
                                         IDocumentRepository documentRepository, IEventAggregator eventAggregator)

and e.g. the IDocumentRepository is passed in because the JobsModule which uses this presenter contains
        protected void RegisterViewsAndServices()
            _container.RegisterType<IJobsView, JobsView>();
            _container.RegisterType<IJobsViewPresentationModel, JobsViewPresentationModel>();

This is fine without using WF however as soon as you start using custom activities whiich exist as independant types what's the best way to pass them in to the activities or resolve them directly within the activity? E.g. a JobDeliverActivity would deliver a job activity to a specific user through email. It would need to access the IDocumentRepository for data access.  
You could make all the possible repositories or types registered through all the containers in the whole application and modules exist as properties on the workflow object itself and then each activity could presumably access them through the ActivityExectionContext however that doesn't seem ideal.

Any thoughts?

Nov 20, 2008 at 12:15 PM
Any thoughts appreciated :)
Nov 20, 2008 at 9:15 PM

I found from my previous research note archive the following link, which should help you forward.  You do need to do some experimental coding and fit that to your need but the idea of one possible solution is there. See the this and Ruurd series of this topic from link below.


Nov 20, 2008 at 9:37 PM

I also found another note which I made while I was heavily following Unity code drops. If you are just targeting to WPF then this concept could also be another way to approach. Please note that this only will work on WPF not on Silverlight.


Anyhow Denis did a good experimental coding earlier on this subject and he walkthroughs and explains on his series how to do IoC Injection with Unity Application Block by using Markup Extensions.


If you want to get more flexibility in lower level this could be one way to solve it in your WF/WPF application. Again, you do need to do some experimental coding here as it’s not str8 forward but hopefully gives you some thoughts and ideas more.

See Denis series on link below:!305B02907E9BE19A!307.entry