Minggu, 23 Januari 2011

Unit Testing with .NET RIA Services


Vijay, one of the folks working on RIA Services recently posted a very good overviewimage of how to do Unit Testing with .NET RIA Services. I think this is an important benefit of adopting the RIA Services pattern.

Check it out and let us know what you think!




Unit Testing Business Logic in .NET RIA Services

New MSDN Article on RIA Services Published


I saw Maurice de Beijer recently published a good introduction article on .NET RIA Services. image

Getting started with the .NET RIA Services

The post starts with a very good introduction:

RIA, short for Rich Internet Applications, is a bit of an umbrella term for all sorts of applications delivered through the browser. The key aspect however is that they deliver some business function and are not just about flashy graphics. Business applications tend to work with data and other business resources so they are usually built in the standard N tier architecture. If we take a look at this N tier architecture for the most common type of business resource, the database, we typically see the Create, Read, Update, Delete, (CRUD) pattern appear all the time. While implementing the CRUD pattern in Silverlight isn’t extremely difficult the very fact that the Silverlight application runs in the browser without direct database access and all server communication is done asynchronously makes this harder than it needs to be. This is exactly one of the problems the .NET RIA Services is trying to solve. Of course there is more to the .NET RIA Services and the standard CRUD operations is just one of the issues addressed. As we will see in this article it addresses much more by including things like data validation, general communication, keeping client and server code synchronized and more.

When evaluating the .NET RIA Services we should be looking at it from two different perspectives. First of all it is a set of design guidelines of how to create a RIA style application. Secondly it is a series of .NET libraries and Visual Studio templates implementing the design guidelines. So even if you don’t want to use the .NET RIA Services binaries, studying the design is very useful for a Silverlight line-of-business (LOB) developer. Another thing to keep in mind when evaluating the .NET RIA Services is that it is not just about Silverlight but more general. The first samples may be with Silverlight clients but a client could equally well be written in ASP.NET/JavaScript, WPF or any other client that can call WCF services.

Enjoy!

.NET Rocks! on Data Access Options


Recently .NET Rocks! talked to Stephen Forte and covered a topic I have been interested in for a a couple of years: Data Access Options. Clearly this has been a space of a lot of innovation in the last few years. Stephen does a good job of explaining the benefits customers are getting out of that innovation but he also gives us at Microsoft a few points to consider on the technology options.

imageOf course one of my favorite parts starts right at the end when Richard asks Stephen about .NET RIA Services. It is about at minute 47 if you want to skip ahead to it ;-). Stephen clearly sees RIA Services as more than Silverlight as it hooks into ASP.NET… he also sees how it shields the developer from the unnecessarily complex code.

Enjoy!

Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 1: Navigation Basics


With Silverlight 3 shipping and a brand new update to .NET RIA Services I thought I would update the example from my Mix09 talk “building business applications with Silverlight 3”.

You can watch the original video of the full session

The demo requires (all 100% free and always free):

  1. VS2008 SP1 (Which includes Sql Express 2008)
  2. Silverlight 3 RTM
  3. .NET RIA Services July '09 Preview (optional for this part of the demo)

Also, download the full demo files and check out the running application.

Today, we will talk about Professional Feel..

Professional Feel

Business applications need to have a professional, but how many of us have a full time designer on our staff? I’d guess very few. That is why we invested in a great out of box experience. The Silverlight Navigation Application and Silverlight Business Application (which adds login\logout support) project starts with a clean, prescriptive application structure, a nice look and feel, and is very easy to customize, even for a developer.

File\New Project – Silverlight Business Applications

image

Hit F5

image

Change from Mix: Notice the cool new, clean, light default template.

This is a full frame Silverlight Application. Notice the navigation links (home and about).

image

Notice the forward and back in the browser works…

image

And there is a deep link, that navigates you back to exactly this point in the application. You can cut and paste it into a blog entry, an email or an IM to your co-works and they will be taken to exactly the same point in the app.

image

… no mater what browser they are using.

Now, even the best developers sometimes make errors in applications. Links that are invalid or exceptions that get thrown. The Navigation Application Template makes it super easy to deal with those. Type in a bad URL and look at the experience (be sure to run in retail).

image

Now, let’s go in and look a bit of customization.

First, let’s add a new page.

Right click on Views in the client project and Add New Item, Select Silverlight Page.

image

image

When the page opens, add some simple text..

<TextBlock Text="Hello World!"></TextBlock>




Now, let’s wire up the this page to the main navigation menu. In MainPage.xaml, add a new button following the same format as the ones that are there.





<Rectangle Style="{StaticResource DividerStyle}"/>



 



<HyperlinkButton Style="{StaticResource LinkStyle}" 



                 NavigateUri="/MyFirstPage" 



                 TargetName="ContentFrame" 



                 Content="my page"/>




Now, while we are in there, let’s customize the error window template… Open Views\ErrorWindow.xaml. You can change the format, log the error back to the server or customize the text on the error message the end user sees.





<TextBlock x:Name="IntroductoryText" Grid.Row="0" Margin="0" 



           Text="An unknown error was encountered. Please contact ScottGu anytime day or night (123) 332-9801 for more information." 



           Width="398" TextWrapping="Wrap" HorizontalAlignment="Left"/>




Now, let’s update the branding for this site. First in MainPage.xaml, change the name from “Application Name” to something custom to your app.





<TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}" 



                   Text="Super Employee Placement Service"/>




Finally, let’s go in and change the colors to match your companies branding. Open up the Styles.xaml file in Assets folder. While all the styling is there for you to customize, we made a few of the common properties easy to find and change even for a developer.



image



Fit F5 and see what we have….



image



image



As you can see, my color choices aren’t great, so it is good that we are shipping a whole library of app.xaml files for you to choice from. If you just drag one of the light, clean ones.. hit F5..



You can get all the latest themes from here.. they work just great from VS as well as expression!



http://timheuer.com/blog/archive/2009/07/09/free-silverlight-application-themes-silverlight-3.aspx



Aurora (also available for RIA Services Template):



Aurora app theme



Frosted Cinnamon Toast:



Frosted Cinnamon Toast app theme



Lime Shocker (also available for RIA Services Template):



Lime Shocker app theme



Pinky (also available for RIA Services Template):



Pinky app theme



Retro:



Retro app theme



Skyline:



Skyline app theme



Subdued:



Subdued app theme

Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 3: Authentication


More update on my Mix09 talk “building business applications with Silverlight 3”.


You can watch the original video of the full session


The demo requires (all 100% free and always free):



  1. VS2008 SP1 (Which includes Sql Express 2008)

  2. Silverlight 3 RTM

  3. .NET RIA Services July '09 Preview

Also, download the full demo files and check out the running application.


Today, we will talk about Authentication


Business applications often access very important data. It is important that you can audit, restrict and control access to your data. Let’s look at how to use .NET RIA Services and SL3 to do that.


Using the Silverlight Business Application Template this is super easy to do.. By default it is wired up the ASP.NET authentication system that offers a customizable user management system.


I’ll show using Forms Auth, you can of course use Windows Auth with only very small tweaks to the template.


image_thumb[56]


For this demo, I will show creating a new user, but if you already have a user base you can of course use that.


image_thumb[57]


image_thumb[58]


Notice we get full validation here.


Any now, when we log in the app knows who we are..


image_thumb[59]


Notice all of this UX on the client is completely customizable as all the source code is right there in the project. But the out of box experience is not bad for many apps.


Now that we are logged in, let’s do something with that user data. For example, let’s make it such that only logged in users can access the super employee data. Edit the SuperEmployeeDomainService class on the server to add the RequiresAuthentication attribute. There are other attributes for things like “in role” and there is a way to do this in code if you’d like.



[RequiresAuthentication]
public IQueryable<SuperEmployee> GetSuperEmployees()

Now, when we run this app and we are not logged in we get no data. Notice this validation is done on the client for a good UX and again on the server to ensure security.


image_thumb[60]


Then when we log in we get data!


image_thumb[61]

Silverlight 3 Controls Sample App


Want a quick reference and simple example of how to use all the cool controls in Silverlight 3?

Check out the Silverlight Toolkit Samples

The best part is not only can you run it as a quick reference and get a feel for how the controls work, but you can also get easy access to all the source code!

Here are a few of my favorites!

DataPager

image

DataForm

image

Charting

image

Rating

image

ChildWindow

image

Managed Extensibility Framework (MEF) Preview 6: V1 Feature Complete Silverlight Support and Much More!


Today we released MEF Preview 6 on codeplex. Not only is this the feature complete build for MEF V1.0 (which will ship with .NET Framework 4) but it also has the first drop of MEF for Silverlight!

image

Nick has the best summary of what is new.. but a few highlights:

  • Silverlight support
  • Lazy<T> replaces Export<T>
  • Collection import changes
  • Inheritance changes
  • Export attribute is unsealed
  • Stable Composition makes its debut
  • Please go download the bits (and full source) which works with .NET Framework 3.5 and Silverlight 3 on the CodePlex site.

    As always, we’d love your feedback and thoughts on MEF discussion forum.

    Want to know more about MEF? Check out Jason Olson’s new Video

    10-4 Episode 26: Creating Extensible Applications with the Managed Extensibility Framework

    image