Using Lambda Expressions in Csla.Net property registration

March 4, 2009 13:23 by ndibek

With Csla.Net 3.5 came a concept of "managed properties", properties that automatically handle business and authorization rules, without additional code reguired to wire up all those notifications.  In 3.6 managed properties were extended to allow serializing Csla.Net objects accross different runtimes (.Net to Silverlght).

The thing I do not like about property registration was, while it resembled dependency properties from WP/Silverlight, it required string constants or property names.  And string constants as we know are BAAD! 

So, in 3.6.2 we are adding another way to register properties - using Linq Expression API!  Lets take a look at the example:

    private static PropertyInfo DescriptionProperty = 
      RegisterProperty(p=>p.Description);
    public string Description
    {
      get { return GetProperty(DescriptionProperty); }
      set { SetProperty(DescriptionProperty, value); }
    }

Besides being shorter, this syntax supports full Intellisense, as the only expressions allowed are Property expressions of properties belonging to the object. This is compile time safe.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Adding Custom Themes Support to your WPF Application

November 17, 2008 03:41 by ndibek

The greatest thing about Windows Presentation Foundation is that when compared to Windows Forms, it finally gives us the freedom of easily designing rich UI, that differs from same old Winforms we have been seeing from Win 95 with slight re-styling. We finally have a true vector based UI, that allows us to manipulate each screen element in thousands of different ways through visual effects, animations, scaling, custom layouts etc.

But with this Great Power comes even larger responsibility. Yes we can do all these things, but we also need to assure that our UI looks consistent: If we find this really cool looking buttons library, we need to assure that the Tree Control that we render next to it is styled appropriately to match it, as well as list box, check boxes scroll bars...

We do not want our new UIs to be a mix of every color in the rainbow that look like water color painting of a kindergartner. We need a professional 21st century UIs. Unfortunately most of us developers are superbly creative when it comes to complex algorithms, while our artistic skills lack far behind. Third party controls that support custom Themes might have been a solution to this problem in Windows Forms world, but do we really have to go there in WPF? Another great thing with WPF it adds native support for custom themes. Basically you define your basic layout, drop your controls on the screen, and then similar to CSS in the web world, you define custom styles for your control in the Resources section of your XAML code. If only we had a nice library of WPF styles that we could use...

 



Well that is where "WPF Themes" Library - Open Source Project hosted on CodePlex comes in.  First it is a library of a dozen custom UI Themes for most of the standard WPF controls, allowing us to customize the look and feel of our WPF UI without touching our screens XAML.  What more the library actually comes with a Theme Manager, that allows us to dynamically load and bind our custom Themes at runtime.

How can we use these Themes?  Obviously first download WPF Themes Library project from http://www.codeplex.com/wpfthemes and include it in your WPF Solution. Then it is a matter of you deciding how do you want to select and load custom Theme at runtime.  For the purpose of this example lets presume that we want to allow our Application user to select any of these Themes at runtime in a form of the Drop Down box that we place at, lets say, top right corner of the application main screen.

So lets define this DropDown:

Ok, so if we look at the XAML above you will notice that there is a stack panel that encapulates the label and a DropDown. But wait, there is no event handler for the SelectionChanged event! How do we tell this WPF Theme library to load a theme we select from the DropDown? Well, if we take a look at the source code of the ThemeManager class that is in charge of loading Themes for us, you will notice that it defines/registers a Dependency Property called "Theme". What does that mean? It means that we can just add this propery to our root window, and bind it to the drop down selection, and that is it. Each time we change a selection in our Drop down list of available themes, ThemeManager loads that Thema and applieas it to our WPF application. The two lines of XAML that allow us to define our dependency property are listed below:



    ...

Now the last question is: How do we populate the "Available Themes" Drop Down list? We simply bind it to ThemeManager.GetThemes(), like below:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    themes.ItemsSource = ThemeManager.GetThemes();
}

And simply put - that is it, by placing the code above together with WPF.Themes project in your solution you get great set of WPF themes, that you can simply use in your app, but also customize and extend.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Sarah gets pranked

November 2, 2008 00:18 by ndibek
Yet another gem from Sarah Palin. I got this one from Aaron. Enjoy!
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

TeamCity - an excellent .Net Continuous Build Environment

October 21, 2008 08:30 by ndibek

Having worked with CruiseControl.Net for years, and understanding the slow adoption of that valuable tool due to simply too high learning path for soemone who needs to quickly setup an automated build system, TeamCity promised to be an interesting alternative.

Naturally there is a TFS also, but the problem with the TFS is that it is huge, provides much more than Continous Integration - there is the Source Control and Work Item tracking.  And if you already have an existing source control like SVN, and an existing item tracking(BugTracker.Net), migration of all that to TFS just to gain the automated build capabilities is simply too much work.  Not to mention the added cost of several thousands of dollars.

So I downloaded and installed a free "Professional Edition" of TeamCity.  With this free edition one gets a CI server with support for up to 20 developers and 20 build configurations, with a limit of 3 build agents  - allowing us to have builds queued up on 3 separate computers. 

 What trully amazed me was that I had this server installed, configured and then my first build configuration setup against the version control and running in a matter of 10 minutes or so.  Everything was easy and intutitive.  I highly recommend it for folks that are new to the Continuous Integration and need to setup solution quickly and without a hassle.

 It appears that all of the major Source Control systems are supported, with the exception of Source Gear Vault.  Supported .NET platform build runners are:

  • MSBuild
  • NAnt
  • Microsoft Visual Studio Solutions
    • 2003
    • 2005
    • 2008
  • Duplicates Finder for Visual Studio 2003, 2005 and 2008 projects (C# up to version 2.0 and Visual Basic .NET up to version 8.0)

Plus you can select the Command Line runner and use any script to build your projects. 

 

 All in all this appears to be an excellent product.  Check it out for yourself at:

http://www.jetbrains.com/teamcity/ 

 

Team City - Project Build History
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

CSLA.NET VB and C# Visual Studio Class Templates

October 17, 2008 09:02 by ndibek

As a part of upcoming CSLA.NET 3.6 beta 2 release we have added one more feature - Csla.Net Class Templates for VB.NET and C# integrated in Visual Studio 2008.  So for example, when you select "Add New Item" in Visual Studio you get following options: 

Each of the class templates from the dialog above generates a Csla object with the template selected.  So for example, for selected CommandObject template in the dialog above with the selected name CommandObject2 you get the code generated below:

using System;
using System.Collections.Generic;
using System.Text;
using Csla;
namespace ClassLibrary1
{
[Serializable]
public class CommandObject2 : CommandBase
{
#region Authorization Methods
public static bool CanExecuteCommand()
{
// TODO: customize to check user role
//return Csla.ApplicationContext.User.IsInRole("Role");
return true;
}
#endregion
#region Factory Methods
public static bool Execute()
{
if (!CanExecuteCommand())
throw new System.Security.SecurityException("Not authorized to execute command");
CommandObject1 cmd = new CommandObject1();
cmd.BeforeServer();
cmd = DataPortal.Execute(cmd);
cmd.AfterServer();
return cmd.Result;
}
private CommandObject1()
{ 
/* require use of factory methods */ 
}
#endregion
#region Client-side Code
// TODO: add your own fields and properties
bool _result;
public bool Result
{
get { return _result; }
}
private void BeforeServer()
{
// TODO: implement code to run on client
// before server is called
}
private void AfterServer()
{
// TODO: implement code to run on client
// after server is called
}
#endregion
#region Server-side Code
protected override void DataPortal_Execute()
{
// TODO: implement code to run on server
// and set result value(s)_result = true;
}
#endregion
}
}
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Bye Bye MS AJAX, Welcome JQuery

September 28, 2008 12:56 by ndibek

Finally the news that some of us in the ASP.NET MVC World have been secretly hoping for, has come true. Microsoft will ship JQuery as a part of ASP.NET inside Visual Studio - IntelliSense and all!  Not just that - it is to be the basis of any of their new Ajax UI widgets and elements they design in ASP.NET.

But why trust me, check from the source himself - Scott Guthrie:

http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx

For some of you that might have dropped out if this planet for the past year or two,  JQuery is a very powerful, yet simple JavaScript/Ajax framework that allows for a effective manipulation of Html elements without much of the script.  For details please check out:

http://www.jquery.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

An interesting migration problem from "Linq to Sql" to "Linq to Entities"

September 15, 2008 07:09 by ndibek

As you might have seen  from few of my previous posts I have been working on the MVC demo implementing Csla.  DAL layer of that demo used the Repository pattern, which is essentially just a wrapper around Linq2Sql DataContext:   

 
Then we would have one implementation of IRepository for each Linq to Sql table / DTO object, like for example SqlCustomerRepository.GetAll(), SqlOrdersRepository.GetAll(), etc.
 
All that each of the GetAll() methods would do is return (this is the implementation in SqlCustomerRepository):
 
 
where _db is an instance of the Linq DataContext.  Hiding DataContext away from our BO and abstracting it away from business layer objects makes it easier to test our business objects.  It makes it easy to replace the SqlCustomerRepository, with TestCustomerRepository that might return hard-coded list of Customers instead.
 
Then we use this inside our business object applying necessary filters - all that the method returns is IQueryable<T> so it makes it easy to use result of GetAll() in another Linq query:
  
 
One problem Rocky noticed in this design is that we are returning Linq generated DTOs.  What if our application needs to migrate to Oracle as a back end, for example.  The only option then is Linq to Entities.  But the type generated by Linq to Entities is different than type generated by Linq to Sql.  Although they might have similar signatures they are different objects.
 
One solution would be t create generic Data Transfer Objects that are neither  Linq to Sql neither Linq to Entities and then "map" the either implementations to these "shared" objects that are instead sent as DTOs.  Problem - one would have to hand code all that stuff.  
 
So for now I decided to give up on Linq to Sql in my demo and migrate it to Linq to entities.  Having 2 different database back ends would not matter in Entity Framework as either Sql Server or Oracle tables are mapped into Entities.  But that meant migrating to Linq to Entities.
 
I thought that this will present not much work at all as the queries are rather simple, and both frameworks support the same Linq syntax.  So I regenerated my Entity diagram using EF.  Everything compiled - good!.  
 
But when I ran the application - I got the following error:
 
Only parameterless constructors and initializers are supported by LINQ to Entities.
 
So although it compiled as perfectly valid Linq Query, at runtime it broke due to the fact that Linq to Entities can not evaluate expression if there are constructors with parameters, or initializers that are not an anonymous objects.  Took me a while to wrapmy head around that statement, but that essentially is what EF team states.  You can check it out in greater detail on following two sites:
 
Essentially Linq2Entities was complaining about:
 
select new OrderInfo(order)
 
part.   OrderInfo is the BO that is part of the list I am trying to populate from EF Entity - order, which is passed as a parameter to its constructor.  So essentially I had to modify the Fetch() method to following:
 
 
 
So what changed?  We are selecting the "order", which is the Linq to Entities object, and then we have to iterate through the list of those objects to map one at the time (as can be seen from use of Add() method instead of AddRange() which was used in Linq to Sql version).
 
Yet another "feature" that any of us migrating from Linq to Sql to Linq to Entities should be aware of.
  
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC Site using Csla and ExtJs - Part 3 - UI, ExtJs Customer DropDown List

September 10, 2008 09:32 by ndibek

This is the third part in series "Implementing MVC Site using Csla and ExtJs".  The first two parts can be found here:

Part 1 - Introduction 

Part 2 - Solution Structure 

 

In the previous 2 posts I mentioned decisions behind some of the technologies used in the demo as well as the file structure.

 If you remember I stated that url reguest like:

http://server/<Controler>/<Action>/<Parameter(s)>

is mapped into Controller.Action(Parameters...) call.

So lets take a look at the  our example - what happens when we click on Customer link:

As you can see the url follows the pattern we mentioned above.  So with the assumption from above we would presume that the CustomerController.List() method would be called.  Lets take a source code of that Action/Method to se how do we get to the view:

Where is the beef? List method seems to create some SelectList object, and then passes it to the method called View as a parameter.  Hmmm...  OK, method View probably results in View called List being rendered, and we are passing it SelectList for perhaps databinding...

Where is CSLA code?  Well, customerFactory is an instance of ReadOnlyListFactory class.  RetreiveAll() returns CustomerList instance which is ReadOnlyBase implemenation.  But why not use  CustomerList.RetreiveAll() - factory method?  Instead of using Factory Method design patern, we are using Abstract Factory, moving Create(), and Fetch() outside of our Csla BOs, for the purpose of easier Unit Testing.  I will explain the details of this in one of the future posts that has to explain the whole process of testing all of the app layers in Csla - which will probably be the best part of this demo.

For now, all we need to know is that there is AbstracBusinesstFactory class that defines following: 

 
and then the ReadOnlyListFactory.RetreiveAll() looks like this: 
 
and cutsomerFactory is instantiated with, in controller's constructor with:
 
var customerFactory = new ReadOnlyListFactory<CustomerList,CustomerInfo>();
 
Again all we care for now is that customerFactory.RetrieveAll() serves same purpose as customerList.RetriieveAll().
 
What does then SelectList object do?  It is used by Html.DropDownList() helper method of the MVC frameowrk (there are number of others) that renders html  <select>element for us.  All that SelectList does is it takes the IList implementation, like CustomerList, the other two parameters being Key Value (CustomerID)and  Display Value (CustomerName), for SelectList.
 
Lets now take a look at the Html source of the List.aspx: 
 
This actually is all of the Html that is in the List.aspx view, by the way.  I will explain later how the Order and OrderDetials grid "Magically" appear on it.
 
  

But wait, when I run the sample site the drop down I see has a different style from standard windows drop-down.  In addition to that we can see that the drop down has a type-ahead, kind of like Intelisense...

How come?  When I look at the html source very simple <select> element is rendered... 

Simply put this is where ExtJs comes in.  We have used ExtJs DropDown control, that simply can "inherit" from the Html element/instance, and extend it to implement some new functionality, like in this case.  What complicated JS did we have to write to do this, you might ask?
 
Well here it goes, this is all that is needed:
 
It appears that the script creates an Instance of Ext.form.ComboBox() class (I know, I know some of you might say: "But wait JS does not support classes".  Well ExtJs does, and so does JQuery, and Prototype - 3 most popular Ajax libraries on the planet). And it passes parameters, like typeAhead: true, and transform:'customerList'.  TypeAhead is obvious, but transform parameter is interesting.  It tells ExtJs.for.ComboBox class which html <select> element it needs to enhance/transform.  And that is all.  Oh, by the way there is an extra call that registers JS function refreshOrderGrid() to listen to "select" event on our drop-down, after the constructor.  That is the extCombo.addListener() call.
 
But Nermin, we should not use JavaScript, although that chunk of code looks cool.  Well then neither should folloing companies, all of which have sites built on top of ExtJs:
 
Adobe, Aetna, AIG, Alcatel-Lucent, Amazon.com, Best Buy, Boeing, Borland, CA, Canon, Capgemini, Cisco, CNN, Dow Jones & Co., EMC, Fidelity, General Electric, Hallmark, HP, HSBC, IBM, Mott MacDonald, NATO, NetApp, Nortel, Northrop Grumman, Panasonic, Pixar Animation Studios, Qualcomm, Inc., S&P, SAP, Siemens, Sony, Symantec
 
The difference between the JS that used to get us burned in the old ASP days and ExtJs is that ExtJs is extremely simple, it is used strictly for UI rendering - no business logic in JS, and allows for all of the modern language constructs in JS.  Building extension methods, overloads, custom expressions is easier in ExtJs than in C#.  And would you rather have unreadable and unmaintainable Java Script that some of the Web Forms control generate (that by the way is not compatible with all of the browsers, and can't be touched - it is generated), or would you use this easily extensible JavaScript  library directly.  Unlike Web Forms generated script this is easily manipulated for style, adding new features etc.  One can inherit from Ext.form.ComboBox class create its own extenions override existing methods behaviors.  Limit is only your cretivity.
 
This will just get more interesting in the next post when we discuss the "magically" appearing Order, and Order Detail grids. Grids that support everything that ASP.NET Web Forms GridView do and lot more.  And it is my humble hope that the article will prove to you that this results in by far simpler and easier to maintain code, that is easily testable, and more stable.
 
Source for this demo can be found at:

ExtJsDemo.zip (2.58 mb)

 
 
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC Site using Csla and ExtJs - Part 2 - Solution Structure

September 10, 2008 06:34 by ndibek

This is the second article in "Implementing MVC Site using Csla and ExtJs".  There will be few more!  First one can be found at:

Part 1 - Introduction 

Unfortunately I have to get through this part and UI before I starttalking about my favorite parts TDD using MVC, Unit Testing in Csla,Design of the DAL in this example to support testability, and newfeatures of Csla 3.6 that support Unit Testing, like ObjectFactory. This part being UI, and how Csla BOs get rendered in MVC app that usesExtJs Ajax library.  Fortunate part about that though is that I hopemany of you will find the UI part to be something different and cool! 

So lets take a look at the ExtJsMvc solution (image on the left).  It includes 3 projects:

- ExtJsCslaDemo.Web (web site)

-  ExtJsCslaDemo.Web.Test (Unit tests library built on top of xUnit.net and RhinoMocks)

- Northwind.Data (Linq DAL + few classes that make testing a DAL breeze, on all on top of Northwind sample DB - attached in App_Datafolder)

 

Key to any Web MVC project are the following 3 folders:

- Controllers (controller classes are in this folder)

- Views (This folder contains all the Views/Pages to be rendered inthis application.  Views are grouped in Subfolders that hold the samename as a controller that is in charge of that view.  SO for example,you have a Customer subfolder of the Views folder that holds veiws thatthe CustomerController controls - a single veiw called List.aspx).

- Models (This is the place for your BOs that the Views will render- in this example, this is where I placed the Csla classes, butobviously for any solution that ).

 

As far as controllers our focus is going to be strictly onCustomerController, and OrderController.  HomeController is just thedefault one that gets created by the MVC project wizard, andAccountController is the one that takes care of security (login,changing passwords, etc).

 When it comes to views just notice that Customer Controller has oneview (List.aspx), while OrderController has no views in the Views/Orderfolder.  I will explain that part later in the UI section. 

 Source for this demo can be found at:

ExtJsDemo.zip (2.58 mb) 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

An Issue with [HandleError] attribute in MVC and JQuery Ajax Load()

September 10, 2008 04:59 by ndibek

In CTP release 4 of MVC frameowrk for Asp.Net we have seen an introduction of [HandleError] attribute that can be assigned to a Controller class or individual Action methods.  It works great.  It captures any unhandled exceptions thrown by your code, and redirects to the default error Handling page/view Error.aspx that displays the exception detail.

The behavior can be fine-tuned further to have different pages for different exception types, or different Action methods.  But I have found one scenario where this attribute does not work, but could easiuly be addressed.

 Lets imagine a scenario where lets say you are builing a wizard.  Your primary view gets loaded as a container for wizard pages, and then you want each of your actual pages to be loaded inside a panel on your wizard.  Obviously you want to avoid post-backs, and you want to load those wizard pages as Ahax loaded partials.

In other words, Ajax call invokes a call on your controller that renders the Html for your page, and then your Ajax/JScript libary inserts that HTML at pre-destined place on your page.  Simple.

 Except that for this case, when error hapens inside the Controller that reneders my partial page I get nothing - no expected page and no error page either.  So what is the problem? Take a look at the source code of the HandleErrorAttribute.OnException() method (I used Reflector to get to it):

 

 
As you can see in the last 2 lines we clear the existing Response stream and return a StatusCode of 500.  Ajax libraries, like the one I used - JQuery, assume that the 500 is "Internal Server Error", and do not load/get the actual Html.
 
Solution to this problem:  I built my own HandleErrorAjaxPartial that inherits from HandleError and overrides the OnException() method, calling the base.OnException() and resetting StatusCode to OK (instead of 500).  Then all of the Controller actions that render wizard pages and are called from my Ajax code got marked with this new attribute, and now everything is fine.
 
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC site using CSLA and ExtJs – Part 1 - Introduction

September 8, 2008 02:19 by ndibek

There are many folks who simply believe that one can’t develop a Test Driven MVC site using CSLA.NET.  Two just simply won’t work together!  CSLA.NET is just too tightly coupled! MVC and TDD require a specific DI architecture that simply cannot work with CSLA’a mobile objects.  Well we are here to disprove those assumptions.  In addition this will be the first step towards creating a CSLA standard bearer demo site in MVC – Project Tracker. 
This is going to be a multi-part post where each post will describe different parts of this MVC application, and different Csla integration points – Introduction – MVC part, Json UI, Unit Testing, and the choice of Repository Pattern for this demo. 

History

You can download the source here.   But before we go through the example what was my motivation behind this.  ASP.NET forms few years back represented one of the largest productivity increases in web development.  But soon we discovered that complex layouts require complex web controls and pages.  In addition to that none of the complex controls are easily extended, beyond simple tasks that are built into the control itself (style, and similar changes on a grid control, for example).  Awkward event model that was supposed to make it easier for Windows developer’s to migrate to web became another bottleneck.  The largest problem was that although we were coding ASP.NET web apps in .Net languages, our deployment target was still a combination of JavaScript/Html, the part that was almost completely abstracted away and hard to get to.
That abstraction was a reason for making any extensions to existing ASP.NET web controls and libraries harder.  For some controls like grid control for example, we did not even know what html is going to be rendered at run time.  It depended on browser type, version, time of the day,…  Worst of all when Ajax came out, technology that heavily depended on JavaScript/Html ASP.NET started falling behind some of the competitors.  For sure we got few little things like “Update Panels”, and little auto-completion fields (that somebody else built for us), but building anything yourself required JavaScript.  Not just that but integrating that JavaScript to run with the ASP.NET Server components was not the easiest thing in the world.

Concepts

That is where the idea of MVC came to life (actually few other competitors have had successful implementations before .Net, and even on .Net platform there was a Monorail platform that was available years before ASP.NET MVC).  Instead of having a web page/form respond to URL requests and Html form posts, they introduced a controller object.  And they came up with a simple mapping that allowed us to build rather simple public methods on the controller and map Html form values or URL query parameters to that method as parameters or directly onto a DTO object inside that method.  That separation resulted in easier program control flow from server to the web page, and breaking away from server side control model.  Pages became views, in charge of nothing but rendering a content and presenting it to the user, as well us posting changed data to the controller.  There was no more any complex business logic on the page itself, or complex "server event flow".

So if you would see a URL like:
http://server.com/Products/Edit/5,
that would map into a ProductController.Edit(5) action method.

I am not going to go though full introduction of MVC here.  You could go through the documentation/examples on following site:
http://asp.net/mvc
http://www.codeplex.com/aspnet
http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx

Demo App

So this example (screen below) utilizes MVC Framework for ASP.NET and is built on top of CTP 5.

ExtJsDemo.zip (2.66 mb)

 

 At the back end of this demo is a copy of the Northwind database (found in App_Data folder).   It is a simple screen with 3 ReadOnlyList object.  On the left you will see a Drop Down with a list of customers.  Once a Customer is selected, we load a list of Orders for that Customer.  When selected, order displays its order details in the drop down below.  

All of the actions on this screen utilize Ajax calls.  Now for the choice of Ajax framework used here.  MS Ajax as it is built is out of questions.  It was built to support web form post back/callback model, which really cannot take advantage of the MVC model.  And simply put it is not very easy to use outside web forms.  AS far as MS MVC Ajax – MS folks have just started working on it for the latest CTP 5 release, and they are years behind ExtJs, Jquery, and other libraries.

That leaves us with JQuery and ExtJs (at least fro now).  However, one good thing about MVC framework, is that is built from scratch to be easily extensible, and to play well with any of the third part tools.  You will see in some of my future posts on this demo that I utlize xUnit.net and excellent unit test framework that drives the innovations in .Net unit testing world.  Not nUnit, or MSTest. Or for the same reason choice of RhinoMocks as the Dynamic Mocking framework.  For the same purpose in the future versios of this demo we will utilize StructureMap as a Dependency Injection framework instead of MS Unity.  All of these play very well with MVC and prove how extensible it is.  But enough about that - lets mov on with our demo solution.

There are conceptual differences with the JQuery and ExtJs.  JQuery is more focused on building dynamic html with its Ajax calls to the server, and dynamically inserting modifying parts of the page in response to Ajax action.  If for example you want to render a custom modal pop-up dialog inside the page, as a result of action on the page JQuery will submit action to the server – controller, that will then render the content of the dialog back to the page.  JQuery will then insert the dialog inside the modal frame control and display it.  That is more in line with traditional Ajax development.


My choice of the ExtJs had something to do with a lot of CSLA developers coming from the Windows world.  ExtJs actually provides us with the visual components/controls, like grids, drop downs, tabs, windows, etc…  This controls utilize JSon to submit modified data to the server, and receive the content they need to render from the server.  So instead of receiving a content of the grid control, for example, as a partial html page (table element), from the controller action, ExtJs grid actually receives what is called a JSon reader, and binds it to a sortable/ customizable grid control.


That way our server MVC model; actually utilizes more of a familiar control/event model on the client and I would actually say that for Windows developers this might be even easier migration path than the web forms.
In the next post I will be talking about UI portion of this demo, provide details of how we convert Csla objects into Json stream, send it from the Controller action and then utilize it within ExtJs Drop Down and Grid controls.  This post will mostly be about server side unit testing for controller and routes.  The fourth and final post should focus on the choice of Data Access Layer pattern – repository, and its integration into Csla code.

ExtJsDemo.zip (2.66 mb)

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Few more words on Chrome

September 3, 2008 02:58 by ndibek

If my previous post about Chrome has you thinking about it, but you are still unsure whether you would want a BETA software installed on your computer, following blog posts explains pretty much all of the features of the Chrome browser:

http://blogoscoped.com/google-chrome/ 

And it is all packaged in a nice visual story.

 

Enjoy! 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Google's Chrome Shines

September 2, 2008 07:15 by ndibek

So what is Google Chrome?  It is a new Web Browser. But before you say: "Enough, I can't keep track of IE7/8, Mozilla, Safari, now I have to take a look at yet another browser!!!", there is something interesting and different about this one.

 It appears that the Google team has been writing a browser from scratch, not worrying about baggage like what is found in IE or Mozilla.  It is Open Source so they have been able to take existing bits and pieces from other projects as needed - shortening development time, and at the same time adding a ton of completely new stuff.

First reason to take a look at this browser would be:

- How many times do you deal with IE that fails to load one of the tabs, end up locking the whole browser process, and there is nothing you can do about it but kill the process.  Mozilla is a bit better, but to me it seems that it is "allergic" to Flash.  

Chrome's Solution:  Each Page loads in its own Process.  There is no way that JavaScript failing on one page can hang the whole browser - you just get what they call "Unhappy Tab".  Each Tab manages its own memory and garbage collection, assuring that once the tab is closed all of its memory is released, which is not the case with the other 2 browsers.

Talking about JavaScript - they have build a brand new Virtual Machine for their JavaScript that besides supporting objects also adds support for classes in JavaScript.  Not just that but all of the existing JavaScript objects are assigned to "hidden" JavaScript classes, allowing categorization, and caching.  In addition, there is a built-in performance advantage of VM where JavaScript is compiled and then binary is re-used instead of re-interpreted each time JavaScript is re-executed is priceless.  Google site points to huge performance increases.  I have not run a numbers, but just a visual rendering part of UI components that are generated by JavaScript looks awesome.  I have run Chrome against the ExtJs.com demos - ExtJs being most JavaScript intensive UI/Ajax library, and have not seen yet such a performance out of those components.

From that we move onto rendering engine.  Used with dozen or so web sites - it is flawless.  Smoothest page rendering, and there are no visual differences when compared to IE.  It appears that google.com cached searches help Chrome folks in their automated testing of the layout engine - they virtually have whole of the web at their fingertips.

and finally some typical Google touches:

- if I type "news." in my url bar, I get news.google.com, and news.yahoo.com in the dropdown below it and not 500 articles I have previously visited on those 2 web sites

- when I open a new tab in Chrome, by default I get a sidebar with my most used bookmarks, as well as thumbnails of my most visited pages, allowing me to open one with a single click (image below)

 

All in all this product has left an excellent first impression and even though it is still beta I would recommend everyone to check it out. 

 http://www.google.com/chrome

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SVN Bridge from CodePlex

August 26, 2008 03:46 by ndibek

Working with CodePlex on one of the projects I was faced with dilemma – download TFS explorer to get the latest source code from their TFS server, or…
I was about to give up and download/run a 300 TFS Explorer on my latest development VPC image (project required some beta MS tools; hence the VPC as a development platform, but that is story for some other time).  But then I noticed following text:

!! Warning !! - If you use the Team Explorer client then it will add source control binding information into your project files. When users download your source code and try to open it in Visual Studio they will get error messages because of the source control bindings. You can use any of the other available source control clients as an alternative.


So the Codeplex folks do not recommend using Team Explorer?!  Other options included several console tools, and one mentioned TortoiseSVN – which I am using anyways on a daily basis.  It appeared that you can use TortoiseSVN for any of your CodePlex source control operations, as long as you install and sun this SVN Bridge service on your local computer.


So I gave it a try - It is truly simple.  You download the executable from the Codeplex’s site, and run it – that creates a service that runs and can be seen in your windows trey. This service runs as a “fake” SVN server that runs on port 8081 by default and does nothing but translate SVN API calls to remote TFS.

You might wonder how does a call to the “local” SVN repository gets directed to correct CodePlex TFS server.  It is simple:
1)    You create a folder which will contain your project source from TFS.
2)    Right click on the folder in Win Explorer, and using SVN Checkout command of your Tortoise client, bring up the Checkout dialog.
3)    The format for your checkout URI is then:
http://localhost:8081/<CodePlex TFS Server domain>/<CodePlex Project Name>


And that is it.  I have tried a number of TortoiseSVN commands including “Repo-browser”.  Everything seems to work fine.  In the weeks and months ahead I will continue to use and evaluate this tool, but as it stands now, it was extremely easy to configure and use.  I highly recommend it.

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

RhinoMocks 3.5 AAA Model

August 22, 2008 03:58 by ndibek

Ayende has again proven why he is one of the most respectednames in Alt.Net community.  Besides writinga book on language based DSLs, supporting Boo, and NHibernate, having a fulltime job, and writing one of the most informative blog publications, he hasactually practically re-written RhinoMocks in this new version.  And with that RhinoMocks basically takes backthe title of simplest and most productive dynamic mocking framework out there.

Take a look at an ASP.NET MVC test written with RhinoMocks3.3: 

 

As you can see the test above uses a traditional Record& Replay model (referred to as R&P in the rest of this document), wherein Record block we generally set our expectations, and then the Replay block isused to perform actions on object being tested, allowing our Mock objects to execute and verify expectations.

Now let’s take a look at the same test written withRhinoMocks 3.5:

 



This test uses Arrange, Action and Assert model (AAA).  What you will notice first is that there areby far fewer lines needed to setup mocks.

In the AAA version there is no need to instantiateMockRepository, once you generate your Mock, or in this case Stub object, youcan setup your expectations directly on the mock instance. Lines 21 and 22 inR&P version of the test are replaced by single line of code in AAA version –line 22.

You will also notice that we are using GenerateStub()instead of DynamicMock().  Put simply thereis a difference between Mock and Stub objects and RhinoMocks recognizes thatallowing us to write tests that better state their purpose.  For some of you scratching your heads,easiest way to describe the difference is to say that Mock objects are used todefine expectations i.e: In this scenario I expect method A() to be called withsuch and such parameters.  Mocks recordand verify such expectations.  Stubs, onthe other hand have a different purpose: they do not record or verifyexpectations, but rather allow us to “replace” the behavior, state of the “fake”object in order to utilize a test scenario.

In this case the behavior we want to stub is: “WhenGetCustomers() is called return the testCustomers list.”  You can see that AA version uses a Lambda expressionto define the method being called.  Againthe line 24 in AA version replaces lines 24-30 in R&P version.

And lastly at the end of the AAA version, as we have definedour expectation directly on the mock object itself (which replaced the recordblock), there is no need to define the Playback block either.  It is assumed that it follows the recordedassumptions.  Therefore the Playbacksection of the R&P model is comparable to Action and Assert sections of theAA model.

So as you can see our tests have dropped from 13 down to 7lines of code.  Also due to a lot simplermocking portion of the block tests are now lots easier to read and maintain.  I must add that this is only the portion ofthe new features Ayende is adding to RhinoMocks, and for more details I wouldrefer you to go to RhinoMocks wiki as well as Ayende’s blog.  Personally I would like to congratulate himon making a good Dynamic Mocking tool great.

http://ayende.com/Wiki/Default.aspx?Page=Rhino%20Mocks%203.5&AspxAutoDetectCookieSupport=1#WhatsNewinRhinoMocksDF

 

 

 kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5