BusinessRx Community

Dedicated to the advancement of software, technology and the people who devote their lives to it.

Welcome to BusinessRx Community Sign in | Join | Help
in Search

BusinessRx Reading List

These blog entries are written by industry experts and leaders. We consider this content to be a good read for any software developer or web technologist.

May 2008 - Posts

  • ASP.NET MVC Preview 3 Release

    This morning we released the Preview 3 build of the ASP.NET MVC framework.  I blogged details last month about an interim source release we did that included many of the changes with this Preview 3 release.  Today's build includes some additional features not in last month's drop, some nice enhancements/refinements, as well as Visual Studio tool integration and documentation.

    You can download an integrated ASP.NET MVC Preview 3 setup package here.  You can also optionally download the ASP.NET MVC Preview 3 framework source code and framework unit tests here.

    Controller Action Method Changes

    ASP.NET MVC Preview 3 includes the MVC Controller changes we first discussed and previewed with the April MVC source release, along with some additional tweaks and adjustments. 

    You can continue to write controller action methods that return void and encapsulate all of their logic within the action method.  For example:

    which would render the below HTML when run:

    Preview 3 also now supports using an approach where you return an "ActionResult" object that indicates the result of the action method, and enables deferred execution of it.  This allows much easier unit testing of actions (without requiring the need to mock anything).  It also enables much cleaner composition and overall execution control flow.

    For example, we could use LINQ to SQL within our Browse action method to retrieve a sequence of Product objects from our database and indicate that we want to render a View of them.  The code below will cause three pieces of "ViewData" to be passed to the view - "Title" and "CategoryName" string values, and a strongly typed sequence of products (passed as the ViewData.Model object):

    One advantage of using the above ActionResult approach is that it makes unit testing Controller actions really easy (no mocking required).  Below is a unit test that verifies the behavior of our Browse action method above:

     

    We can then author a "Browse" ViewPage within the \Views\Products sub-directory to render a response using the ViewData populated by our Browse action:

    When we hit the /Products/Browse/Beverages URL we'll then get an HTML response like below (with the three usages of ViewData circled in red):

    Note that in addition to support a "ViewResult" response (for indicating that a View should be rendered), ASP.NET MVC Preview 3 also adds support for returning "JsonResult" (for AJAX JSON serialization scenarios), "ContentResult" (for streaming content without a View), as well as HttpRedirect and RedirectToAction/Route results.  

    The overall ActionResult approach is extensible (allowing you to create your own result types), and overtime you'll see us add several more built-in result types.

    Improved HTML Helper Methods

    The HTML helper methods have been updated with ASP.NET MVC Preview 3.  In addition to a bunch of bug fixes, they also include a number of nice usability improvements.

    Automatic Value Lookup

    With previous preview releases you needed to always explicitly pass in the value to render when calling the Html helpers.  For example: to include a value within a <input type="text" value="some value"/> element you would write:

    The above code continues to work - although now you can also just write:

    The HTML helpers will now by default check both the ViewData dictionary and any Model object passed to the view for a ProductName key or property value to use.

    SelectList and MultiSelectList ViewModels

    New SelectList and MultiSelectList View-Model classes are now included that provide a cleaner way to populate HTML dropdowns and multi-select listboxes (and manage things like current selection, etc).  One approach that can make form scenarios cleaner is to instantiate and setup these View-Model objects in a controller action, and then pass them in the ViewData dictionary to the View to format/render. 

    For example, below I'm creating a SelectList view-model class over the set of unique category objects in our database.  I'm indicating that I want to use the "CategoryID" property as the value of each item in the list, and the "CategoryName" as the display text.  I'm also setting the list selection to the current CategoryId of the Product we are editing:

    Within our view we then just have to write the below code to indicate that we want to create a drop-downlist against the SelectList we put into ViewData:

    This will then render the appropriate drop down with items and selection for us at runtime:

     

    Built-in error validation support isn't included with our HTML helpers yet (you currently need to write code for this) - but will show up in the future, which will make form editing scenarios even easier.

    You'll also start to see ASP.NET AJAX helper methods show up in future preview releases as well, which will make it easier to integrate AJAX into MVC applications with a minimum of code.

    URL Routing Improvements

    ASP.NET MVC Preview 3 includes a number of improvements to the URL routing system.  URL routing is one of the most "fundamental" components of a web MVC framework to get right, hence the reason we've spent a lot of focus the first few previews getting this area nailed.  Our new URL routing engine will ship in .NET 3.5 SP1 this summer, and will support both Web Forms and MVC requests.  ASP.NET MVC will be able to use the built-in .NET 3.5 SP1 routing engine when running on .NET 3.5 SP1. ASP.NET MVC will also include its own copy of the assembly so that it can also work on non-SP1 systems.

    Some of the URL Routing Improvements in the Preview 3 release include:

    MapRoute() and IgnoreRoute() helper methods

    ASP.NET MVC Preview 3 includes new "MapRoute" and "IgnoreRoute" helper methods that you can use to more easily register routing rules.  MapRoute() provides an easy way to add a new MVC Route rule to the Routes collection.  IgnoreRoute() provides an easy way to tell the URL routing system to stop processing certain URL patterns (for example: handler .axd resources in ASP.NET that are used to serve up JavaScript, images, etc). 

    Below is an example of the default RegisterRoutes() method within Global.asax when you create a new ASP.NET MVC project where you can see both of these new helper methods in action. 

    The MapRoute() helper method is overloaded and takes two, three or four parameters (route name, URL syntax, URL parameter default, and optional URL parameter regular expression constraints). 

    You can call MapRoute() as many times as you want to register multiple named routes in the system.  For example, in addition to the default convention rule, we could add a "Products-Browse" named routing rule like below:

    We can then refer to this "Products-Browse" rule explicitly within our Controllers and Views when we want to generate a URL to it.  For example, we could use the Html.RouteLink view helper to indicate that we want to link to our "Products-Browse" route and pass it a "Food" category parameter using code in our view template like below:

    This view helper would then access the routing system and output an appropriate HTML hyperlink URL like below (note: how it did automatic parameter substitution of the category parameter into the URL using the route rule):

    We could alternatively use the new Url.RouteUrl(routeName, values) within views if we wanted to just retrieve the URL for a named route (and not output the <a> html element). 

    We could also use the new RedirectToRoute(routeName, values) helper method on the Controller base class to issues browser redirects based on named routing rules. 

    Richer URL Route Mapping Features

    ASP.NET MVC Preview 3 also supports a bunch of new URL route mapping features.  You can now include "-", ".", ";" or any other characters you want as part of your route rules.

    For example, using a "-" separator you can now parse the language and locale values from your URLs separately using a rule like below:

    This would pass appropriate "language", "locale", and "category" parameters to a ProductsController.Browse action method when invoked:

    URL Route Rule Example URL Parameters Passed to Action method
    {language}-{locale}/products/browse/{category} /en-us/products/browse/food language=en, locale=us, category=food
      /en-uk/products/browse/food language=en, locale=uk, category=food

    Or you can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format:

    This would pass both "category" and a "format" parameters to the ProductsController.Browse action method when invoked:

    URL Route Rule Example URL Parameters Passed to Action method
    products/browse/{category}.{format} /products/browse/food.xml category=food, format=xml
      /products/browse/food.html category=food, format=html

    ASP.NET MVC Preview 3 also supports wildcard route rules (these were also in Preview 2).  For example, you can indicate in a rule to pass all remaining URI content on as a named parameter to an action method:

    This would pass a "contentUrl" parameter to the WikiController.DisplayPage action method when invoked:

    URL Route Rule Example URL Parameters Passed to Action method
    Wiki/Pages/{*contentUrl} /Wiki/Pages/People/Scott contentUrl="People/Scott"
      /Wiki/Pages/Countries/UK contentUrl="Countries/UK"

    These wildcard routes are very useful to look at if you are building a blogging, wiki, cms or other content based system.

    Summary

    Today's Preview 3 release of ASP.NET MVC includes a bunch of improvements and refinements.  We are starting to feel good about the URL routing and Controller/Action programming model of MVC, and feel that those areas are starting to bake really well.  In future preview releases you'll start to see more improvements higher-up the programming model stack in areas like Views (html helpers, validation helpers, etc), AJAX, sub-controllers and site composition, deeper Login, Authentication, Authorization and Caching integration, as well as data scaffolding support. 

    I also have a (very) long tutorial post that I started putting together this past weekend that walks-through building an application using ASP.NET MVC Preview 3 that I'm hoping to wrap up and post in the next few days.  This should provide both a good intro to ASP.NET MVC, as well as help provide some context on how all the pieces fit together if you are interested in using the ASP.NET MVC option.

    Hope this helps,

    Scott

  • Twitter

    The most annoying thing about Twitter being down is that you can't *** to your twitter friends about Twitter being down.

    -James

  • A New Tutorial Series on Master Pages

    Over the past two years I've been working on a number of step-by-step tutorials for Microsoft's www.asp.net website. The two complete tutorial series are:

    I'm happy to announce a new tutorial series of mine on the www.asp.net website on master pages. The first three tutorials are now available:

    • Creating a Site-Wide Layout Using Master Pages [VB | C#] - covers the basics of what master pages are and how to use them to define a site-wide layout.
    • Multiple ContentPlaceHolders and Default Content [VB | C#] - a master page can contain multiple ContentPlaceHolders. It's also possible to define default markup for a ConentPlaceHolder. Content pages can either emit this default content or override it with custom content.
    • Specifying the Title, Meta Tags, and Other HTML Headers in the Master Page [VB | C#] - typically the <head> section of a web page is contained in the master page and not the content page, so what do you do if the content page needs to define page-specific <head>-level markup? This tutorial shows how to customize the page's title, meta tags, and other HTML headers.

    There will be a total of 10 tutorials. The next batch focuses on common master page challenges - creating non-breaking URLs and control ID naming and referencing, among other topics.

    Like my past tutorials, these tutorials are all available in C# and VB versions, include a complete working source code download, and are available to download as PDF, as well.

    Enjoy! - http://asp.net/learn/master-pages/

  • Rob's Not So Lazy MVC Storefront

    Rob ran into some lazy load problems in his MVC Storefront and later proclaimed:

    "…if you set any Enumerable anything as a property, it's Count property will be accessed when you load the parent object. This negates using any deferred loading for any POCOs, period"

    Rob thought this was a problem with .NET in general, but I was suspicious. Veeery suspicious. I downloaded Rob's latest bits and found some interesting behavior.

    Based on the screen shot of the call stack that Rob posted, it appeared LINQ to SQL was doing some type conversions. If you poke around the classes mentioned in the call stack, you'll eventually wander into a GenerateConvertToType method that uses LCG to build dynamic methods. Just based on the opening conditional logic, I thought Rob might solve his problem by using LazyList<T> for his business object properties, too (whether or nor he'd want to is a different question), so I modified his Category class for a few experiments to see what would really lazy load.

    public class Category {

        
    // rob's original
        public IList<Product> Products { get; set; }
        
        
    // experimental
        public LazyList<Product> ProductsLazy { get; set; }
        
    public IQueryable<Product> ProductsQueryable { get; set; }
        
    public IEnumerable<Product> ProductsEnumerable { get; set; }

        
    // ...

    This was in hopes that LINQ to SQL wouldn't feel compelled to do a conversion via List<T>. I just needed to tweak the query to set all four properties.

    var result = from c in db.Categories
                
    join cn in culturedName on c.CategoryID equals cn.CategoryID
                
    let products = from p in GetProducts()
                     
                 join cp in db.Categories_Products
                        
                on p.ID equals cp.ProductID
                          
         where cp.CategoryID == c.CategoryID
                    
                select p
                 select new Category
                 {
                     ID = c.CategoryID,
                     Name = cn.CategoryName,
                     ParentID = c.ParentID ?? 0,
                     Products =
    new LazyList<Product>(products),
                     ProductsQueryable = products,
                     ProductsEnumerable = products.AsEnumerable(),
                     ProductsLazy =
    new LazyList<Product>(products)          
                 };
                 return result;

    This experiment failed in a stunning fashion, because none of the Product properties lazy loaded – they all eagerly populated themselves full of real product objects. Hmmm.

    Slight Detour

    Watching SQL Profiler, I started to wonder why there were soooo many queries running. Sure, the stuff wasn't lazy loading but the queries were flying by quicker than eggs at a Steve Ballmer talk. Yet, the code that was kicking off the whole process was just looking for a single category:

    Category result = _repository.GetCategories()
                                 .WithCategoryID(id)
                                 .SingleOrDefault();

    That problem turned out to be in Rob's WithCategoryID extension method.

    public static IEnumerable<Category> WithCategoryID(
        
                                     this IEnumerable<Category> qry, int ID) {

        
    return from c in qry
              
    where c.ID == ID
              
    select c;
    }

    By taking an IEnumerable<T> parameter, the extension method was forcing the query to execute and then doing all the ID checks using LINQ to Objects. Just switching over to IQueryable<T> made the method a lot more efficient, and the number of queries came down tremendously.

    Correlating Problems

    Back to the original problem, which was a bit of a mystery because I've been able to lazy load collections using IEnumerable<T> and IQueryable<T>. After some more fiddling, I began to suspect the query itself. The query uses a correlated subquery by virtue of the fact that the range variable c is used inside the query for products (c.CategoryID). I'm guessing that LINQ to SQL felt compelled to take care of all the work in one fell swoop. Instead of using a subquery, I presented LINQ to SQL with a method call that pushed the needed parameter (c.CategoryID) onto the stack, and made things slightly more readable in the process.

           var result = from c in db.Categories
                        
      join cn in culturedName
                           
    on c.CategoryID equals cn.CategoryID
                       

                        let
    products = GetProducts(c.CategoryID)
                       

                        select
    new Category
                        {
                            ID = c.CategoryID,
                            Name = cn.CategoryName,
                            ParentID = c.ParentID ?? 0,
                            Products =
    new LazyList<Product>(products),
                            ProductsQueryable = products,
                            ProductsEnumerable = products.AsEnumerable(),
                            ProductsLazy =
    new LazyList<Product>(products)                    
                        };
          
    return result;

       }

      
    public IQueryable<Product> GetProducts(int categoryID)
       {
          
    var products = from p in GetProducts()
                          
    join cp in db.Categories_Products on p.ID equals cp.ProductID
                          
    where cp.CategoryID == categoryID
                          
    select p;
          
    return products;
       }

    And voila! Three of the properties (ProductsQueryable, ProductsEnumerable, ProductsLazy) would lazy load their Products from the database. Only the original IList<Product> property would eagerly fetch data. From what I can decipher in the grungy code, when LINQ to SQL sees it needs to assign to an IList<T>, and it doesn't have an IList<T>, it eagerly loads a new List<T> and copies those elements into the destination. At least, that's my theory.

    Knowing what I know now, I could tell Rob to stick with IList<T> as his property type, but to make sure he has IList<T> on both sides of the assignment in his projection (and tuck the product query into a method call). In other words, use the following to create the LazyList<T> - LINQ to SQL won't load up Products during some wierd type conversion:

    public class LazyList<T> : IList<T> {

       
    public static IList<T> Create(IQueryable<T> query)
        {
        
        return new LazyList<T>(query);
        }

        // ...

    Conclusion? Beware of mismatched types, particularly with IList<T>, and watch out for eager execution with correlated subqueries.

  • May 20th Links: ASP.NET, ASP.NET AJAX, .NET, Visual Studio, Silverlight, WPF

    Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately.  Below is a new post in my link-listing series to help kick things up a little.  Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past.

    ASP.NET

    • ASP.NET Perf Issue: Large numbers of application-restarts due to virus scanners: Tess Ferrandez has a great post that details a debug session to determine why an ASP.NET application was restarting frequently (causing performance slowdowns).  The issue was a virus scanner that was causing files to be constantly updated.  Make sure to check out the logging code you can add to your application to identify restart causes like this.

    ASP.NET AJAX

    .NET

    • 7 Ways to Simplify your code with LINQ: Igor Ostrovsky has a great blog post that talks about new code techniques you can use to improve your code using .NET 3.5 and the new language and LINQ features in it.

    • Visual LINQ Query Builder for LINQ to SQL: Mitsu Furuta has created a cool Visual Studio designer that allows you to graphically construct LINQ to SQL queries.  Also make sure to download download the latest LINQPad utility - which is invaluable for learning LINQ and trying out LINQ queries.

    • Ukadc.Diagnostics: Josh Twist pointed me at a new CodePlex project he is working on that extends the System.Diagnostics features in .NET to include richer logging features (SQL trace support, email support, etc).

    Visual Studio

    Silverlight

    • Silverlight 2 Pie Chart: Peter McGrattan has posted a nice control and article that demonstrates how to use a new Silverlight charting control he has written.

    WPF

    • WPF week on Channel9: Watch 6 great videos on Channel9.  Each one includes interviews and demos with members of the WPF team talking about some of the awesome work that went into WPF 3.5 SP1 (read my blog post here for a summary of some of it).

    • WPF Testing and Application Quality Guide: Check out the 0.2 release of a free online book being developed by Microsoft that covers how to test WPF applications.  Definitely worth book-marking if you are doing WPF development.

    • WPF 3.5 SP1 StringFormat: Lester has a nice post that describes how to use the new StringFormat feature in WPF 3.5 SP1.  This makes it much easier to handle formatting of databound values.

    Hope this helps,

    Scott

  • Visual Designers Don’t Scale

    Microsoft has a long history of being visual. They've made quite a bit of money implementing graphical user interfaces everywhere – from operating system products to database servers, and of course, developer products. What would Visual Studio be if it wasn't visual?

    And oh how visual it is! Visual Studio includes a potpourri of visualization tools. There are class diagrams, form designers, data designers, server explorers, schema designers, and more. I want to classify all these visual tools into one of two categories. The first category includes all the visual tools that build user interfaces – the WinForms and WebForms designers, for instance. The second category includes everything else.

    Visual tools that fall into the first category, the UI builders, are special because they never need to scale. Nobody is building a Windows app for 5,000 x 5,000 pixel screens. Nobody is building web forms with 5,000 textbox controls. At least I hope not. You can get a pretty good sense of when you are going to overwhelm a user just by looking at the designer screen.

    Visual tools that fall into the second category have to cover a wide range of scenarios, and they need to scale. I stumbled across an 8-year-old technical report today entitled "Visual Scalability". The report defines visual scalability as the "capability of visualization tools to display large data sets". Although this report has demographics data in mind, you can also think of large data sets as databases with a large number of tables, or libraries with a large number of classes - these are the datasets that Visual Studio works with, and as the datasets grow, the tools fall down.

    Here is an excerpt of a screenshot for an Analysis Services project I had to work with recently:

    Here is an excerpt of an Entity Data model screenshot I fiddled with for a medical database:

    These are just two samples where the visual tools don't scale and inflict pain. They are difficult to navigate, and impossible to search. The layout algorithms don't function well on these large datasets, and number of mouse clicks required to make simple changes is astronomical. The best you can do is jump into the gnarly XML that hides behind the visual representation.

    I'm wondering if the future will see a reversal in the number of visual tools trying to enter our development workflow. Perhaps textual representations, like DSLs in IronRuby, will be the trick.

  • The Emergence of Choice in the .NET Ecosystem

    Last week I gave a talk at the local .NET User Group (TRINUG). The original title of the talk was "10 Open Source Tools you Should be Using", but then I decided that I didn't really know what tools people should be using and I didn't want to just pick the popular open source tools... so I changed the name to "10 Open Source Tool I Love". This way I could just talk about 10 tools that I love and not tell people what to do, then I decided that I hated one of the tools but I still thought it was valuable... so I changed it to "9 Open Source Tools I Love and 1 I kind of hate". But then I figured that was a little too crazy and that I needed a good enterprisey title for the talk and settled on "The Emergence of Choice in the .NET Ecosystem".

    In the past couple of years, and greatly accelerating in the last 12 months, the choices you have as a .NET developer have greatly increased. There have always been alternatives around, Mono and the Castle project have been around forever, but never before has there been so many choices and have those different choices been so widely accepted. What I find especially interesting is that Microsoft is even encouraging choice (ASP.NET MVC vs. WebForms. IronRuby & IronPython, etc). It also seems like the community in general is warming up to alternatives instead of just following the Microsoft path, perhaps this is just me and the circles I frequent, but I really see more activity in adopting non-Microsoft endorsed technologies.

    The main reason for this post is to post a link to my powerpoint for the talk and to post the list of tools I talked about and the resources and alternatives. You can see the powerpoint on slideshare (or download it) but be warned I don't put much on my slides so it's mostly useless.

    Here are the tools I covered:

    1. ASP.NET MVC

    I know its not really open source, but I had to include it. I have heard people dismissing ASP.NET MVC as a tool for the "test obsessed" or "pattern people" but in my opinion it is the most important thing to come out of MS in years.

    ASP.NET Resources
    Scott Guthrie’s Blog
    Phil Haacked’s Blog
    Rob Conery MVC Storefront

    ASP.NET Alternatives
    MonoRail
    Classic ASP.NET + URLRewriting.NET + MVP Pattern

    2. NHAML

    I love the ruby Haml so I knew I would love NHAML. I doubt this will become a mainstream tool, but I love to see alternative implementations to the normal asp.net syntax.

    NHAML Resources
    Andrew Peter’s Blog (creator of Nhaml)
    MVCContrib Codeplex
    MVCContrib Google Group

    NHAML Alternatives
    Nvelocity

    3. jQuery

    I am fairly new to Jquery but so far I am loving it. I have much more experience with Prototype. The real point of including JQuery was to point out the power of these javascript frameworks.

    JQUERY Resources
    Learning Jquery
    FlyDom Plugin

    JQUERY Alternatives
    Prototype
    Scriptaculous
    Mootools
    ExtJS

    4. Castle ActiveRecord

    I love NHibernate and Castle ActiveRecord makes NHibernate even more enjoyable and usable.

    Castle ActiveRecord Resources
    Nhibernate
    Nhusers Google Group

    Castle ActiveRecord Alternatives
    SubSonic
    Entity Framework

    5. SQLite

    This isn't really a .NET tool, but its a great tool for running clients in off-line mode or just as a simple light database. I love using it as a testing database so my tests run fast and they don't clutter up my other database.

    SQLite Resources
    ADO.NET Provider
    SQLite Administrator

    SQLite Alternatives
    SQL Server Compact Edition
    NOT SQL Server Express - Installation and size limitations mean Express is not competition for SQLite.

    6. MbUnit

    MbUnit has long been my testing framework of choice, xUnit.NET is more and more compelling though.

    MbUnit Alternatives
    nUnit
    xUnit.NET

    7. Moq

    I am not a mocking fanatic and usually only mock out external dependencies or long running operations. I have used Rhino.Mocks in the past but I wanted to show off the simplicity of Moq.

    Moq Alternatives
    Rhino.Mocks
    Typemock (commercial)

    8. Ninject

    I am just starting to get into DI (still not sure the value is worth the complexity yet) but Ninject would definitely be my framework of choice because it helps me avoid XML.

    Ninject Alternatives
    Castle Windsor
    StructureMap

    9. Watin
    I am a long-time fan of Watir and Watin so I wanted to be sure and feature it (even though isn't as necessary when using ASP.NET MVC)

    Watin Resources
    Watin Test Recorder

    Watin Alternatives
    WatiR

    10. Cruise Control.NET
    Cruise Control.NET is the tool that I hate. I love the benefit, but it is a total pain in the ass to setup and get running the way you want.

    Cruise Control.NET Alternatives
    TeamCity (semi-commercial)

    If you have any other alternatives for the tools I talked about please leave a comment and I will add it to the post. I have an example app that includes samples from all of these tools as well, but I want to clean it up a little bit then I will post it to Google code. (I also have some other plans for it that should be alot of fun)

    -James

  • ALT.NET Podcast is live

    The ALT.NET Podcast is now up and running. Mike Moore did a great job finding great guests and facilitating such a great conversation for the first episode. I really like the conversational tone of the podcast vs. your normal interview format. I think the podcast will also serve as an excellent introduction to the alt.net community for people who are on the sidelines and not sure where to start or what to make of alt.net.

    You might also notice that I am handling the sponsorship of the the podcast, this is an area where I hope to grow The Lounge as I believe that podcasts offer a unique opportunity for companies to connect with an engaged audience.

    -James

  • Talking at Trinug tonight

    I will be giving a talk about open source tools (and which ones are some of my favorites) at the Triangle .NET User Group tonight. If you want a different look at how to do .NET development then I think you will have a good time. I am covering 10 tools and have demos planned for almost all of them, so it should be an exciting time.

    For more information click here.

    -James

  • Announcing The Ruby Room

    After a long-time in planning I am thrilled to announce that the Ruby room of the Lounge is now up and running. With the help of Geoffrey Grosenbach we have put together some of the best Ruby and Ruby on Rails blogs around as the starting lineup:



    Obie Fernandez is the CTO/Founder of HashRocket, a boutique web consultancy and product shop headquartered in Jacksonville Beach, Florida. Obie has a well-read blog and speaks at conferences and technical user groups on a regular basis. He is also a series editor and book author for Addison-Wesley.



    Geoffrey Grosenbach has been one of the premiere Rails bloggers since 2005 with articles covering the intersection of graphic design and website development. He co-authored "Deploying Rails Applications" and is the founder of PeepCode Screencasts.



    The Softies on Rails are Brian Eng and Jeff Cohen, two former Microsoft Certified Professionals who discovered the joy of developing web applications with Rails in 2005 and have never looked back. Softies on Rails takes a unique look at Ruby and Rails development for those coming from a Microsoft background.



    Jamis Buck has been blogging about Ruby and Rails since 2005, focusing on elegance and opinions in software design. He is the author several well-known open-source Ruby libraries and applications, including the popular remote-automation utility, Capistrano.

    I look forward to seeing this room grow in terms of advertisers and new publishers.

    -James

  • The Power of Programming With Attributes

    Nothing can compare to the Real Power of programming with attributes. Why, just one pair of square brackets and woosh – my object can be serialize to XML. Woosh – my object can persist to a database table. Woosh – there goes my object over the wire in a digitally signed SOAP payload. One day I expect to see a new item template in Visual Studio – the "Add New All Powerful Attributed Class" template: *

    [Table]    
    [
    DataObject]
    [
    DataContract]    
    [
    Serializable]
    [
    TwoKitchenSinks]      
    [
    CLSCompliant(true)]        
    [
    DefaultProperty("Name")]
    [
    DefaultBindingProperty("Name")]
    [
    DebuggerStepThroughAttribute]
    [
    GuidAttribute("F0DD2CAA-2132-11DD-AC50-FE9355D89593")]
    public class Person
    {
        [
    Column]        
        [
    DataMember]        
        [
    XmlAttribute]
        [
    Browsable(true)]
        [
    ReadOnly(false)]
        [
    Category("Advanced")]
        [
    Description("The person's name")]        
        
    public string Name { get; set; }

        
    // TODO: YOUR INSIGNIFIGANT BIZ LOGIC GOES HERE...
    }

    Which begs the question – could there ever be a way to separate attributes from the class definition?**

    * Put down the flamethrower and step away - I'm kidding.

    **This part was a serious question.

  • Warning the User When Caps Lock is On

    After my first batch of Security Tutorials were published on www.asp.net, a reader emailed me asking if it was possible to display some sort of warning if the user has Caps Lock on whilst entering their password into the Login control. While JavaScript cannot indicate if Caps Lock is on or not, you can ascertain whether it is once the user types an alphabetic key, as JavaScript can determine the key pressed and whether the Shift key was also pressed. In short, if the character is upper case and Shift is not depressed, or if the character is lowercase but Shift is depressed, then it follows that Caps Lock is on.

    So it is possible to write a bit of JavaScript that fires when the user types a key into a TextBox and display some warning in response. This ASP.NET Forums post - Give Warning When Caps Lock On - discusses a JavaScript-based solution. The downside is that you have to paste in the necessary JavaScript into the page and add JavaScript to the TextBox control's onkeypressed client-side event. Wouldn't it be easier to be able to drag and drop a control onto the page, set a few properties and, presto, have a working Caps Lock warning?

    My latest 4Guys article, Warning the User When Caps Lock is On, looks at building such a control. It is now part of my skmControls2 collection, which includes (currently) two other open-source server controls:

    For more open-source, free tools, controls, and other funery, check out My Code Projects.

    Enjoy!

  • Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta

    Earlier today we shipped a public beta of our upcoming .NET 3.5 SP1 and VS 2008 SP1 releases.  These servicing updates provide a roll-up of bug fixes and performance improvements for issues reported since we released the products last November.  They also contain a number of feature additions and enhancements that make building .NET applications better (see below for details on some of them).

    We plan to ship the final release of both .NET 3.5 SP1 and VS 2008 SP1 this summer as free updates.  You can download and install the beta here.

    Important: SP1 Beta Installation Notes

    The SP1 beta released today is still in beta form - so you should be careful about installing it on critical machines.  There are a few important SP1 Beta installation notes to be aware of:

    1) If you are running Windows Vista you should make sure you have Vista SP1 installed before trying to install .NET 3.5 SP1 Beta.  There are some setup issues with .NET 3.5 SP1 when running on the Vista RTM release.  These issues will be fixed for the final .NET 3.5 SP1 release - until then please make sure to have Vista SP1 installed before trying to install .NET 3.5 SP1 beta.

    2) If you have installed the VS 2008 Tools for Silverlight 2 Beta1 package on your machine, you must uninstall it - as well as uninstall the KB949325 update for VS 2008 - before installing VS 2008 SP1 Beta (otherwise you will get a setup failure).  You can find more details on the exact steps to follow here (note: you must uninstall two separate things).  It is fine to have the Silverlight 2 runtime on your machine with .NET 3.5 SP1 - the component that needs to be uninstalled is the VS 2008 Tools for Silverlight 2 package.  We will release an updated VS 2008 Tools for Silverlight package in a few weeks that works with the VS 2008 SP1 beta.

    3) There is a change in behavior in the .NET 3.5 SP1 beta that causes a problem with the shipping versions of Expression Blend.  This behavior change is being reverted for the final .NET 3.5 SP1 release, at which time all versions of Blend will have no problems running.  Until then, you need to download this recently updated version of Blend 2.5 to work around this issue.

    Improvements for Web Development

    .NET 3.5 SP1 and VS 2008 SP1 contain a bunch of feature improvements targeted at web application development. 

    The VS Web Dev Tools team has more details (including specific bug fix details) on some of the VS specific work here.  Below are more details on some of the work in the web-space:

    ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)

    .NET 3.5 SP1 adds support for a rich ASP.NET data "scaffolding" framework that enables you to quickly build functional data-driven web application. With the ASP.NET Dynamic Data feature you can automatically build web UI (with full CRUD - create, read, update, delete - support) against a variety of data object models (including LINQ to SQL, LINQ to Entities, REST Services, and any other ORM or object model with a dynamic data provider).

    SP1 adds this new functionality to the existing GridView, ListView, DetailsView and FormView controls in ASP.NET, and enables smart validation and flexible data templating options.  It also delivers new smart filtering server controls, as well as adds support for automatically traversing primary-key/foreign-key relationships and displaying friendly foreign key names - all of which saves you from having to write a ton of code.

    You can learn more more about this feature from Scott Hanselman's videos and tutorials here.

    ASP.NET Routing Engine (System.Web.Routing)

    .NET 3.5 SP1 includes a flexible new URL routing engine that allows you to map incoming URLs to route handlers.  It includes support for both parsing parameters from clean URLs (for example: /Products/Browse/Beverages), as well as support to dynamically calculate and generate new URLs from route registrations.

    This new routing engine is used by both ASP.NET Dynamic Data as well as the new ASP.NET MVC framework.  It will support both WebForms and MVC based requests. 

    ASP.NET AJAX Back/Forward Button History Support

    .NET 3.5 SP1 adds new APIs to ASP.NET AJAX to allow you to better control the history list of a browser (enabling you to control the behavior of the back/forward button of the browser).

    You can learn more about this feature in the article here and the screencast here.

    ASP.NET AJAX Script Combining Support

    .NET 3.5 SP1 introduces a new <CompositeScript> element on the <asp:ScriptManager> server control, which allows you to declaratively define multiple script references within it.  All the script references within the CompositeScript element are combined together on the server and served as a single script to the client, reducing the number of requests to the server and improving page load time for ASP.NET AJAX applications.

    The script combining feature supports both path based scripts and assembly resource based scripts, and dynamically serves up the combined scripts using the ScriptResources.axd handler.

    Visual Studio 2008 Performance Improvements HTML Designer and HTML Source Editor

    In February we released a HotFix roll-up that included a number of performance improvements and bug fixes for the VS 2008 Web Designer.  VS 2008 SP1 includes all of these fixes, as well as a number of additional performance improvements.

    Visual Studio 2008 JavaScript Script Formatting and Code Preferences

    Visual Studio has for several releases supported rich source code formatting options for VB and C# (spacing, line breaks, brace positions, etc).

    VS 2008 SP1 adds richer source code formatting support for JavaScript as well (both inline <script> blocks and .js files).  You can now set your Javascript coding preferences using the Tools->Options dialog:

    These preferences will be automatically used as you type new Javascript code in the source editor.  You can also select existing code, right-click, and choose the "Format Selection" option to apply your style preferences to existing JavaScript code.  You can learn more about this new feature here.

    Better Visual Studio Javascript Intellisense for Multiple Javascript/AJAX Frameworks

    VS 2008 includes Javascript Intellisense support in source view.  The intellisense support with the initial VS 2008 release works well with vanilla JavaScript as well as code written using the ASP.NET AJAX JavaScript type patterns.  JavaScript is a very flexible language, though, and many JavaScript libraries use this flexibility to full advantage to implement their features - sometimes in ways that prevented the intellisense engine from providing completion support.

    VS 2008 SP1 adds much better intellisense support for popular Javascript libraries (we specifically did work to support JQuery, Prototype, Scriptaculous, ExtJS, and other popular libraries).  You will get better default intellisense when you reference these libraries.  We are also looking at whether we can maintain additional intellisense hint files that you can download to get even better intellisense and documentation support for some of the more popular libraries.

    Below is an example of using a JQuery startup function with the VS 2008 SP1 JavaScript intellisense engine:

    Notice below how VS 2008 SP1 can now provide method argument completion even on chained JQuery selectors:

    Visual Studio Refactoring Support for WCF Services in ASP.NET Projects

    VS 2008 SP1 adds better refactoring support for WCF services included within both ASP.NET Web Site and ASP.NET Web Application Projects.

    If you use the refactoring support to rename the class name, interface contract, or namespace of a WCF service, VS 2008 SP1 will now automatically fix up the web.config and SVC file references to it.

    Visual Studio Support for Classic ASP Intellisense and Debugging

    Previous versions of Visual Studio included support for intellisense and debugging within classic ASP (.asp) pages.  The file and project templates to create classic ASP pages/projects hasn't been in VS for a few releases, though, and with the initial VS 2008 we incorrectly assumed this meant that people weren't still using the classic ASP support.  We heard feedback after we shipped that indeed they were. 

    With VS 2008 SP1 this support for classic ASP intellisense and debugging is back:

     

    Visual Web Developer Express Edition support for Class Library and Web Application Projects

    The Visual Web Developer 2008 Express edition (which is free) is being updated in SP1 to add support for both class library and ASP.NET Web Application project types.  Previous versions of Visual Web Developer Express only supported ASP.NET web-site projects.

    Among other benefits, the support of class library and web application projects will enable ASP.NET MVC and Silverlight projects to be built with the free Visual Web Developer 2008 Express.  All of the above JavaScript, Dynamic Data, Classic ASP, and AJAX improvements work with Visual Web Developer Express as well.

    Improvements for Client Development

    .NET 3.5 SP1 and VS 2008 SP1 contain major performance, deployment, and feature improvements for building client applications. 

    Tim Sneath has a great blog post that talks about some of the client improvements here.  Below are more details on them:

    Application Startup and Working Set Performance Improvements

    .NET 3.5 SP1 includes significant performance improvements to the CLR that enable much faster application startup times - in particular with "cold start" scenarios (where no .NET application is already running).  Much of these gains were achieved by changing the layout of blocks within CLR NGEN images, and by significantly optimizing disk IO access patterns.  We also made some nice optimizations to our JIT code generator that allow much better inlining of methods that utilize structs.

    We are today measuring up to 40% faster application startup improvements for large .NET client applications with SP1 installed.  These optimizations also have the nice side-effect of improving ASP.NET application request per second throughput by up to 10% in some cases.

    New .NET Framework Client Profile Setup Package

    .NET 3.5 SP1 introduces a new setup package option for developers building .NET client applications called the ".NET Framework Client Profile".  This provides a new setup installer that enables a smaller, faster, and simpler installation experience for .NET client applications on machines that do not already have the .NET Framework installed.

    The .NET Framework Client Profile setup contains just those assemblies and files in the .NET Framework that are typically used for client application scenarios.  For example: it includes Windows Forms, WPF, and WCF.  It does not include ASP.NET and those libraries and components used primarily for server scenarios.  We expect this setup package to be about 26MB in size, and it can be downloaded and installed much quicker than the full .NET Framework setup package.

    The assemblies and APIs in the .NET Framework Client setup package are 100% identical to those in the full .NET Framework setup package (they are literally the same binaries).  This means that applications can target both the client profile and full profile of .NET 3.5 SP1 (no recompilation required).  All .NET applications that work using the .NET Client Profile setup automatically work with the full .NET Framework.

    A developer can indicate that the client application they are building supports both the .NET Framework Client Profile and the full .NET Framework by pulling up the project properties page for a client application within VS 2008 SP1.  Within the project properties page they can select a new checkbox that indicates it only requires those assemblies included in the .NET Framework Client Profile:

    VS 2008 will then ensure that the project can only reference those assemblies shipped in the client profile setup package (and it will generate a compile error if you try and use a type in an assembly not included in the client redist).  The compiled client application will then run on machines that have both the full .NET Framework installed, as well as machines that only have the .NET Framework Client Profile installed.

    If you have a machine that only has the .NET Framework Client Profile installed, and you try and run a .NET application on it that did not mark itself as supporting the .NET Framework Client Profile, then the CLR will refuse to run the application - and will instead prompt the end-user to upgrade to the full .NET Framework package.  This ensures that applications always run correctly - and that developers do not need to worry about missing assembly exceptions at runtime if a user tries to run an application that requires the full .NET Framework on a machine that only has the .NET Framework Client Profile installed.

    We believe that a large class of .NET client applications will be able to use this new .NET Client Profile setup to significantly speed up their installation, and enable a much more consumer friendly experience.

    New .NET Framework Setup Bootstrapper for Client Applications

    .NET 3.5 SP1 introduces a new "bootstrapper" component that you can use with client applications to help automate making sure that the right version of the .NET Framework is installed. 

    The bootstrapper component can handle automatically downloading and installing either the .NET Framework Client Profile or the full .NET Framework Setup Package from the Internet if your machine doesn't have either of them installed.  The boostrapper can also automatically handle upgrading machines that have a previous version of the .NET Framework installed.  For example, if your machine already has .NET 3.0 installed, and your application requires .NET 3.5, the bootstrapper can optionally download just the update files needed to upgrade it to .NET 3.5 (and avoid having to download the full .NET Framework setup download).

    The setup bootstrapper component can be used with both ClickOnce based setup packages, as well as with third party installer products (like Installshield).  The boostrapper optionally enables fully customized setup branding experiences (splash screens, custom setup wizard steps, etc) and should make it much easier to build optimized client setup experiences.

    ClickOnce Client Application Deployment Improvements

    .NET 3.5 SP1 includes several improvements for ClickOnce deployment of both Windows Forms and WPF applications.  Some of these improvements include:

    • Support for the .NET Framework Client Profile (all ClickOnce features are supported with it)
    • ClickOnce applications can now be programmatically installed through a ‘Setup.exe’ while displaying a customized, branded install UX
    • ClickOnce improvements for generating MSI + ClickOnce application packages
    • ClickOnce error dialog boxes now support links to application specific support sites on the Web
    • ClickOnce now has design-time support for setting up file associations
    • ClickOnce application publishers can now decide to opt out of signing and hashing the ClickOnce manifests as they see appropriate for their scenarios.
    • Enterprises can now choose to run only Clickonce Applications Authenticode signed by ‘Known Publishers’ and block anything else from running
    • FireFox browser extension to support Clickonce installations using FireFox browsers

    Windows Forms Controls

    SP1 adds several new Windows Forms controls - including new vector shape, Printing, and DataRepeater controls:

     

    WPF Performance Improvements

    .NET 3.5 SP1 includes several significant performance optimizations and improvements to WPF.  Some of the specific graphics improvements include:

    • Smoother animations
    • Hardware accelerated rendering of Blur and DropShadow Bitmap Effects
    • Text Rendering speed improvements - especially with VisualBrish and 3D scenes
    • 2D graphics improvements - especially with z-index scenarios
    • A new WriteableBitmap class that enables real-time and tear-free bitmap updates.  This enables custom "paint"-style applications, data visualizations, charts and graphs that optionally bypass the default WPF 2D graphics APIs.
    • Layered window performance improvements

    SP1 also adds support for better data scalability in WPF.  The ListView, ListBox and TreeView controls now support "item container recycling" and "virtualization" support which allows you to easily achieve a 40% performance improvement with scrolling scenarios.  These controls also now optionally support a "deferred scrolling" feature which allows you to avoid scrolling in real time and instead wait until a user releases the scroll thumb (the default scrolling mode in Outlook). This can be useful when scrolling over very large data sets quickly. 

    WPF Data Improvements

    .NET 3.5 SP1 includes several data binding and editing improvements to WPF.  These include:

    • StringFormat support within {{ Binding }} expressions to enable easy formatting of bound values
    • New alternating rows support within controls derived from ItemsControl, which makes it easier to set alternating properties on rows (for example: alternating background colors)
    • Better handling and conversion support for null values in editable controls
    • Item-level validation that applies validation rules to an entire bound item
    • MultiSelector support to handle multi-selection and bulk editing scenarios
    • IEditableCollectionView support to interface data controls to data sources and enable editing/adding/removing items in a transactional way
    • Performance improvements when binding to IEnumerable data sources

    WPF also now exposes hooks that enable developers to write custom panels w/ virtualized scrolling.  We'll be using this support together with the above data binding improvements to build the new WPF datagrid that will be shipping later this year.

    WPF Extensible Shader Effects

    .NET 3.5 SP1 adds support in WPF for a new shader effects architecture and API that allows extremely expressive visual effects to be created and applied to any control or element within WPF.  These shader effects support blending multiple input compositions together.  What makes them particularly powerful is that WPF executes effects (including custom effects you build yourself) using the GPU - giving you fully hardware accelerated graphics performance.  Like almost everything in WPF, you can also use WPF databinding and animation on the properties of an effect (allowing them to be fully integrated into an experience).

    Applying an effect onto a Control is super easy - just set a Control's "Effect" property.  For example, to add a hardware accelerated drop-shadow effect on a button you can use the built-in <DropShadowEffect> on it via either code or XAML:

    Which will cause the button to render like so:

    Because Effects are extensible, developers can create their own custom Effect objects and apply them.  For example, a custom "DirectionalBlurEffect" could be created and added to a ListBox control to change its scroll appearance to use a blur effect if you rapidly scroll across it:

    Keep an eye on Greg Schechter's blog to learn more about how the Effects architecture works and to learn how you can both create and apply new effects within your applications. 

    Note: In addition to introducing the new Shader Effects API, WPF in SP1 also has updated the existing Blur and DropShadow Bitmap effects already in WPF to be hardware accelerated.

    WPF Interoperability with Direct3D

    .NET 3.5 SP1 adds support to efficiently integrate Direct3D directly into WPF.  This gives you more direct access to the hardware and to take full advantage of the Direct3D API within WPF applications.  You will be able to treat Direct3D content just like an image within an application, as well as use Direct3D content as textures on WPF controls. 

    For example, below are three samples from the Direct3D SDK:

    We could either load them in as image surfaces within a WPF application, or map them as textures on WPF controls.  Below is an example of mapping them as textures onto cubes in a WPF 3D application:

    Note: the Direct3D integration isn't today's SP1 beta release.  It will appear in the final SP1 release.

    VS 2008 for WPF Improvements

    VS 2008 SP1 includes several significant improvements for WPF projects and the WPF designer.  These include:

    • Several performance improvements
    • Events tab support within the property browser
    • Ability to sort properties alphabetically in the property browser
    • Margin snaplines which makes form layout much quicker
    • Better designer support for TabControl, Expander, and Grid
    • Code initiated refactoring now updates your XAML (including both control declarations and event declarations in XAML)
    • Go to Definition and Find All References now support things declared in XAML

    The debugger has also been updated in SP1 so that runtime errors in XAML markup (for example: referencing styles, datasources and/or other objects that don't exist) will now be better identified within the debugger:

    Data Development Improvements</