More than one ServiceAgent per ViewModel using Injected Locator?

Mar 26, 2012 at 5:23 PM

Hi Tony,

I have a circumstance where I'd like to use 2 different ServiceAgents within a single ViewModel, and I am wondering if this can be supported with SimpleMvvm's "injected" ViewModelLocator.   (Or maybe there'a a better/easier way to accomplish this?)

Here's my scenario:   I have a "CustomerViewModel" that is mostly about Loading/Saving Customers.   My CustomerViewModel injects an an ICustomerServiceAgent instance, either Mock or Real.   Pretty straightforward and that works great... 

However, a Customer record also has a "Sales Rep" property.   For example, when you edit a customer, there's a ComboBox that allows you to select from a List of SalesReps.  (actually it's a List<User>, but filtered to include just SalesReps, but you get the idea).   The problem is, you retrieve the List of SalesReps using an IUserServiceAgent.    (BTW, you can't edit a SalesRep in the CustomerViewModel - it's just a "Load" operation)

So in the CustomerViewModel, it would be great if I could load (inject) both a ICustomerServiceAgent instance and a IUserServiceAgent instance.  Can I do this with MEF and SimpleMvvm's InjectedViewModelLocator out-of-the-box?   Or does SimpleMvvm allow loading (injecting) just a single ServiceAgent per View Model?   Is there an easy way to do this?

(I know it would be relatively easy to add a GetSalesReps() method to ICustomerServiceAgent, but I'd be duplicating code that is already in IUserServiceAgent, so that is not the desired solution).

Thanks,

Steve