Silverlight 3 Ria Services reference - silverlight

I have a Silverlight project where functionality is segregated across multiple Silverlight libraries due to the size and complexity of the application. I am having problems figuring what is the best way to decouple the RIA Domain Service that gets generated from the Website project. I need to be able to access data from the other libraries as they will be loaded dynamically into the main Silverlight application as needed.

I ended up taking the code that gets generated by Visual Studio in the Generated_Code directory of the main Silverlight application and creating multiple Silverlight libraries to separate the Ria DomainContext, the authentication service, entities, and other Domain services that we had written. I then extracted interfaces for the DomainContext, etc and put them in their own library. Using Microsoft's Unity Framework for Silverlight I was then able to decouple all my modules from the main project. All my modules now use the interfaces. There is one IoC container in the main application where I register all of the classes that implement the interfaces and they get injected into the pages as they are instantiated. Not that compliated after all. The only thing to remember is to leave the EnableClientAccess attribute on the Domain Services classes in the server but remove the ASP.Net server project link from the main Silverlight application. I read that they are planning to make this easier in the final release of Ria services/Silverlight 3 since other people have complained about the tight coupling created by the current setup.

Related

Difference b/w creating a RIA Services Solution and RIA Services class library

what's Difference b/w creating a RIA Services Solution (i.e. Enabling RIA Services checkbox) and RIA Services class library (i.e. using a project template)
What are the functional differences amongst the two?
The library option means you can share it between projects more easily. The solution option is just simpler to get working (not much though).
There is no real functional difference between them. They are just different project structures.
Each RIA services library turns into a web WCF web service library, that you can simply link with your web application and a client side library that you link with your Silverlight client app.
These are not simple class libraries: They are "RIA-linked" together in pairs and generated/shared code from the service library propagates to the matching client library.
Nowadays we always create RIA services libraries in our projects.

MVVMLight, Silverlight, Entity Framework

I have created
a) a basic application MVVMLight framework.
b) another project in the same solution having an Entity Model (NorthwindModel.edmx).
c) a WCF service to retrieve data through the entity model.
Now I want to link a, b, and c together. How do the project mentioned in a) above interact with the other two? How can I display/bind the data using the edmx in the View of the MVVM?
Do I have to write code in the ViewModel class/classes to achieve this?
I browsed through many websites, checked many questions here on SO, but none seems to throw any light for me in this regard. The examples that I saw involved a lot of coding in the ViewModel class. If that's the only way to go about it, then why do people say MVVM with Silverlight requires very little coding?
You can use WCF RIA Services to bridge the gap between ASP.NET and Silverlight.
Get Started - WCF RIA Services
You will need to create a Silverlight library project, add entity files as link to the project.
This will enable you to use the Entities in your Silverlight application.
how to add files as link
Actually you need a Web project where you host your webservices, then you need your business logic layer and data access layer where you retrieve data, then you need the entities and a silverlight entities project. After this you create your Silverlight project and add web service reference to it and thats it, now you are ready to use MVVM.
I think you could use this to refer how to build a solution with multiple projects and also have entity framework with WCF RIA services.
To ensure you project is running MVVM light you could use Nuget to inject the necessary files into your client project. Information on this is available here

Self hosting RIA Services in WPF executable & Referencing SL RIA Class Library

I want to use a RIA Services in WPF (Please hear me out before voting to close this :)).
I learned about being able to use RIA Services for other clients. Also looked at the sample progam (the famous HRApp) for consuming DomainServices from WPF using RIA Services Toolkit.
Unfortunately, none of it gave what I needed (explained below).
I was struck by a thought when I was looking through the walkthrough for making the RIA service client context & the domain services into reusable class libraries.
My idea is this:
Have a SL class library maintain a RIA Link to a Domain Service class library. Reference SL Class library (now extended with my own entity extensions) in WPF. Also Reference the DomainService as a class library and then Self-host using this trick inside my WPF app.
Unfortunately, the code is not compiling if I add System.Windows.dll to my WPF project. (Resharper additionaly complains I need to add System.dll too... but that appears at the moment to be a false alarm).
My needs are this:
Self-host a WCF service that allows me to CRUD (without me writing any code).
The WPF exe that self-hosts can accept connections from instances of the same executable running within LAN with just firewall configuration (where needed). In other words, I want the application to work as a server for its own copies running on other machines OR a standalone client
Just by changing a Option inside the program (or app.config) I can connect to a difference instance (for data consolidation and other processing on the server)
My application is very simple (3 tables at the most). Very simple querying needs
Be able to use ADO.Net Entity Model (and Entity)
Allows me to extend my entity classes akin to what RIA offers
Any pointers as to what my options are would be greatly appreciated.
Thanks in advance.
WCF Data Services was (formerly ADO.Net Data Services & Astoria) what I was looking for. It's remarkably similar to RIA Services.
It satisfies 4, 5, & most importantly #6 of my needs. I was able to self host simply by referencing the Service assembly solving #1, #2. I wasn't really looking for answer for #1 - #3 anyway.

Visual Studio project type for DTOs that should be accessible in Silverlight

What VS project type should I choose so that the data-transfer-objects that I create in it can be accessible in both in my Silverlight project as well as my WCF service project.
(I want to be able to reuse the DTOs that I define in both projects instead of having VS generate a new set in my Silverlight project when I create a web-service reference to the WCF service).
IE, my question is can the project be a Windows class library, or should it be a Silverlight class library (so as to reference it in both my Silverlight project as well as the WCF project).
You've got three main options:
Create two class library projects (one targeting Silverlight, the other the .NET Framework), and share the files between them, as I discuss in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-3.aspx
Create your class library as a Silverlight class library. Silverlight applications can't reference class libraries that target the full .NET Framework, but applications targeting the full .NET Framework (such as you WCF Service) can (generally) reference class libraries that target the Silverlight runtime.
Try out the Portable Library Tools (currently in beta): http://blogs.msdn.com/b/sburke/archive/2011/01/23/3-screen-coding-is-here-portable-library-tools-allow-you-to-target-multiple-net-platforms-with-one-binary.aspx
Have you thought of using RIA Services (or WCF Data Services) instead of a plain WCF service? RIA Services / WCF Data Services handles this problem for you, and adds other great functionality into the mix.
Hope this helps...
Chris Anderson

Silverlight / Prism / RIA : How to create the optimal infrastructure?

Since days I am reading and researching and still struggling how to create the perfect infrastructure. Since there are no Prism 4.0 templates as such, I came up with a strategy, but I need to be sure this is the right strategy and I would appreciate an advice from experienced PRISM/RIA developers.
I use PRISM 4.0, RIA Services 1.0 Sp1 Beta, Silverlight 4.0, Entity Framework 4.0
1) Client side
I created first a "Silverlight Business Application", which creates a Web.host and a Silverlight client application with implemented RIA authorization. The initially created Silverlight client application shall be used as the Shell project.
2) Infrastructure project (Common)
This project would contain some common Prism MEF attributes and perhaps the entity models that are auto generated by RIA as well as the Service Interface. The idea is to create a simple Silverlight Class Library, and under Properties of the project, I would select for the dropdown ‘WCF Ria Services Link ’ to point to the host.Web project that contains the Ria Services. Then after the rebuilding, I am able to see the entity models within the Class Library and these could then be shared between the prism modules to feed their ViewModels etc.
3) Service layer
Should I create the EF4 Model on the Web.host project and add the Domain Service in there? Then I would extract an interface from the Domain Service and put the interface into the Infrastructure (Common) project. The Web.Host therefore needs to reference the Infrastructure (common) project to get access to the interface. On the client side the interface may be used by MEF to retrieve or mock the service . However I am concerned about the service referencing a common project that contains also the client-side generated entities.
4) Authorization
Also a bit concerned about the authorization, shall I leave everything on the Shell project? Or do I have to move anything to the Infrastructure (common) project to share it?
Since this is my first time designing with PRISM, I might have misunderstood or forgotten some aspects. Please feel free to improve my suggestions.
Your help is highly appreciated
Kave
After two weeks of intense research, this blog couldn't put it better together:
http://blogs.msdn.com/b/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx
There're nice Quick Start templates for Prism, I found it at blog http://blogs.msdn.com/b/dphill so it looks quite nice, I used it also created RIA Service library so everything now is separated:
1) WEb project
2) Ria Service on web
3) generated RiaService client code as separate and shared assembly and it is used by modules. that's it.

Resources