Silverlight 4 and WCF RIA Services generated from OlivaNova model
- 3 minutes read - 506 wordsAs stated in a recent post, I’ve been able to create a Silverlight 4 client that accesses an OLIVANOVA generated business logic using WCF RIA Services.
Well, the actual code to enable this scenario is in fact not that complicated (once you learned how to write Silverlight enabled WCF RIA Services). The big advantage for me is that the complete business logic can be generated with OLIVANOVA’s model driven software development approach.
Basically, the code for the DomainService is pretty straight forward and also quite repetitive. Likewise, the XAML within the Silverlight project. So, it was pretty obvious to me that this peace of code could be also generated from the OLIVANOVA model.
I started by creating a new Visual Studio project. To keep it really simple, I created a new ASP.NET website. This application takes the OLIVANOVA model and the target client namespace as an input. Please see the screenshot below:
After clicking on the OK button, this application reads in the information from the model. The desired information I need is basically all the classes along with all their atttributes. Based upon this information, I then generate the following code:
- all entities or rather business objects as plain C# classes.This contains some constructors and all attributes as properties. For the properties I add some standard attributes from System.ComponentModel.DataAnnotations. These attributes include a Key indicator (primary key of that entity) as well as the Display attribute (order of appearance and alias for the user interface).
- all DomainService classes (WCF RIA Sercices). As a first step I only generate one service per entity that retrieves all data from this entity. Again, I make heavy usage of the OLIVANOVA generated framework code in order to access the business logic.
- a Silverlight XAML page per entity. The XAML basically contains the DomainDataSource along with a DataGrid and a DataPager. A DomainContext (specified in the DomainDataSource) references the corresponding DomainService.
- all Silverlight code-behind files for the XAML page. This code actually does not do much more but setting the title of the page to its alias (information from the model).
The last step is then to copy all business object and DomainService source code to the BusinessApplication.Web project. All XAML and code-behind files will be copied to the BusinessApplication project (underneath the Views folder). I then referenced some of the newly generated views in the MainPage.xaml and tested the Silverlight client.
What else could be generated based on information in the OLIVANOVA model?
- the menu or rather navigation of the Silverlight application
- the user interface in more detail (columns in the DataGrid, Master/Detail, service forms to create data)
- DomainService code to get related data (i.e. if I have a relationship between Employee and ExpenseReport, I am able to call a method to retrieve all expense reports for a certain employee)
- basically all DomainService code for CRUD functionality (Create Read Update Delete)
- …
- much more, if you put some more thought into this
Please have a look at some sample screenshots below to see the generated Silverlight client at runtim:.