Generic ServiceAgent

Oct 17, 2012 at 5:57 PM
Edited Oct 17, 2012 at 6:05 PM


Please how can I create a generic ServiceAgent? I have a lot of entities and I would like to avoid implementing a ServiceAgent for every entity. Can you help me find a way to reduce the amount of work? I have more than 100 entities.

It would like to do the same for viewmodels too.


Oct 17, 2012 at 6:34 PM
ServiceAgent exists to abstract away the service from which a ViewModel gets its data. It's not a 1-1 ratio of SA to entity. Normally, it would wrap a call to a WCF service, for example. So you could have just a single service agent to represent your service layer, and include in it several operations returning various kinds of entities. Does that make sense?

Oct 17, 2012 at 7:33 PM

Yes It makes sense, Please can I have an example? I'm using Silverlight5 and Ria Services.

I was trying to do something like this

public interface IServiceAgent<T> where T : class
        void GetAll(Action<List<T>, Exception> completed);
        void Add(T item);
        void Delete(T item);
        void Save(Action<Exception> completed);
        // Reject changes to entities
        void RejectChanges();

then I Implement the ServiceAgent like this
[ServiceAgentExport(typeof(IServiceAgent<Model>), AgentType = AgentType.Real)]
    public class EmployeeServiceAgent : IServiceAgent<Model>
        MyDomainContext domainContext = new MyDomainContext();
I'm sure I am not doing it right.
Thank you for your help.