I have gotten lots of good comments on my series updating my Mix09 talk “building business applications with Silverlight 3”. Some customers have asked about the “live” version I have running on one of Scott Haneslman’s servers (thanks Scott!)
The demo requires (all 100% free and always free):
Scott gave me a FTP access and a web server, but I didn’t want to hassle with setting up a database (though he did offer). So I thought I’d use the POCO support in RIA Services to just get data from plain old CLR objects. Personally, I think far too many of our samples show only Entity Framework… So this is a good excuse to show that off.
So, back to your application diagram, i want to use this post to focus on POCO as a data source.
First, my goal was to make the minimum changes. I didn’t want to touch the client at all, nor did I want to change any of my business logic. I just wanted to move the app from EF\SQL to a POCO data source.
Turns out this was simple enough to do. First I deleted the northwind.mdf file from App_Data then I deleted the EF model.
Then I added a SuperEmployee class.. I went ahead and added the metadata directly.
Then I created SuperEmployeeList class that has all the data
Then I added a couple of simple methods to make encapsulate access.
Then some small tweaks to my DomainService implementation. Notice here I derive directly from DomainService directly rather than using the LinqToSqlDomainService or EntityFrameworkDomainService classes. I think this will be reasonably common..
I should also override Submit to save off the changes (say to a file or some sort of backing store).. but for the demo I wanted to keep them static so no one puts in bad data into my site.
Hit F5 and everything else works.. No changes to the Silverlight client or the ASP.NET client (for SEO).. This same flexibility allows you to move from one data access technology to another without all your clients having to be updated.
As you saw my earlier post, we have a very cool new template that gives you log in and create new user support.
I *had* to enable that in the demo.. At least so folks could play around with it. By default we use the aspnetdb.mdb and SQLExpress… so this needed to be updated just like the above example.
Because we simply plug into the ASP.NET Membership system that shipped in ASP.NET 3.0 this is a pretty well explored and documented area. But here is the brief on it.
In web.config in the server project, under the system.web section add:
Then just implement the SimpleMembershipProvider… Here I did a demo-only model that accepts any user id and password.
Clearly in a real application you will want to plug into your user management system. But, again because ASP.NET’s system has been around for so long there is support out there for just about any system. Also check out a great book on the subject Stefan Schackow’s Professional ASP.NET 2.0 Security, Membership, and Role Management.