Overview of Domain Service Class
On day 2 we ran through creating our first line of business application using RIA services. We did not look deeper much into generated classes. Today we will take a step back and examine Domain Service class. Better understanding on Domain Service class would give us more efficiency to create, share and focus on application logic in between presentation layer and middle layer.
If you go ahead and open solution explorer of project we created on day 2, you will get two projects, one Silverlight and other hosting web project there.
If you remember we added Domain Service class to the web project and we enabled metadata for domain services as well. Due to that you are seeing there is a metadata.cs class in solution explorer.
Open SchoolRIAService.cs and first thing you would notice would be as in below image.
- Attribute EnableClientAccess tells this domain class would be visible to the presentation layer residing at client side.
- The class is derived from LinqToEntitiesDomainService. This is generic abstract class and it is part of WCF RIA Service framework.
- Generic class is taking data model class as input to create domain service.
Next you move further in the class you will find different CRUD methods for different entities from data model. If you have four entities in data model then you will have 16 methods here. For each entity there would be four methods.
Below four methods would perform CRUD operation for Course entity.
In this way you will find CRUD methods for other entities like Departments, OnlineCourses etc
If you remember at time of creating Domain Service class, we checked the check box against entities class to enable editing.
Besides different generated methods you can plug application logic in this Domain Service class. You can modify existing application logic also for example modifying logic behind GetCourse() method.
I will conclude day 3 with assumption that by now you have an overview of Domain Service Class.
See you on day 4
Leave a Reply