views:

477

answers:

2

Hi

I was wondering about how to exactly implement domain service in RIA. Is it common to include all entities in the entire domain model in a single domain service, thus making the service responsible for the entire database? Is this the way it's normally done? I really have no reason to separate data access into different services, but I was wondering if this is considered a good practice, and what the pros and cons of such an approach would be.

Also, is it considered a good or bad practice to register domain context as a singleton with IOC, so that the entire application works with the same set of data, thus avoiding concurrency issues and similar problems?

Thoughts?

Thank you

+2  A: 

We have two separate services in our app: one for the data model and one strictly used for authentication. We took this design from MS's business sample app structure.

We considered breaking up our data domain service into smaller components but decided against it because it didn't seem to add any advantage (other than reducing service class size.) If you have distinct data models that are completely independent from each other then going that route might make sense. Intuitively the domain service should represent the entire domain. If your domains are independent (with the occasional need for crossover) then it makes logical sense to segregate them in that way.

Regarding using the context as a Singleton: I tried that and ended up creating class-scope instances instead. We haven't experienced any issues doing it this way as they all use the same underlying data connection. I don't know what the "official" best practice is, but this is the way I've seen it done in numerous RIA apps.

Nick Gotch
I disagree. I think the domainService should represent a task or business process not the whole domain. A good example app is the Book Club app that you can find here http://www.nikhilk.net/RIA-Services-MIX10-Slides-Code.aspx .
PilotBob
A: 

Thanks Nick. I actually did the same thing as you, I built two services, one for authentication and one for data access. That seems most logical to me.

As for making datacontext a singleton, I've tried that as well and it works nicely. No need to constantly reload and refresh data and worry about concurrency issues in other classes :)

VexXtreme