Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Sunday, December 15, 2013

Building Unity.WebForms (Part 4 of 4)

Injecting dependencies into your Pages, Controls, and Classes

Now that our types have been registered with the container, it is time to see how they get into our pages, controls, and types.

Injecting into Types

When injection into plain old C# classes, we can use any of the mechanisms supported by Unity: Construction, Property, or Method. In the Sample web application we will use the preferred method, Constructor injection, for the Service1 and Service2 classes as follows:

public class Service1
{
public string SayHello()
{
return string.Format( "Hello from Service 1 [Object ID = {0}]", GetHashCode() );
}
}

public class Service2
{
private Service1 _service1;

public Service2( Service1 svc1 )
{
_service1 = svc1;
}

public string SayHello()
{
return string.Format( "{0} (Called from Service2 [Object ID = {1}])", _service1.SayHello(), GetHashCode() );
}
}

Service1 is a basic class with no external dependencies while the Service2 class depends upon the Service1 class. By specifying the dependency in the constructor, the unity container will perform automatic Constructor Injection when resolving the type. The calls to GetHashCode() will show the effect the Lifetime Manager (specified when registering the types with the container) types will have on each service when used.

Injecting into Pages and static User Controls

As mentioned earlier, the ASP.NET pipeline manages the creation of Pages and we cannot override that behavior. As such, we cannot use constructor injection since the ASP.NET runtime knows nothing about Unity. That is why we created the UnityHttpModule which allows us to perform dependency resolution prior to any life-cycle events being called using Property Injection. As the name implies, we simply need place a [Dependency] attribute on any Property we wish to be injected as follows:


[Dependency]
public Service1 InjectedService1 { get; set; }

[Dependency]
public Service2 InjectedService2 { get; set; }

When the BuildUp method of the Unity container is called for a Page and/or User Control that contains the [Dependency] attribute, it will resolve that type of the property and call the setter with the resolved type.

Injecting into dynamic User Controls (or On-Demand injection)

Not all User Controls are added to a page at design time. There are many cases where controls are dynamically added to a page at runtime in response to a certain condition. When this is required, then you will need to ensure that the control gets it dependencies resolved by manually calling the BuildUp method for the newly added User Control as follows:


// dynamically load the new control
InjectedControl newControl = LoadControl("InjectedControl.ascx") as InjectedControl;
// 'buildup' the new control
Container.BuildUp( newControl );
// add the injected control into the page hierarchy
DynamicInjectedControl.Controls.Add( newControl );

To get access to the Container in order to perform the BuildUp, there are 2 options:

  • Add an injected property of type IUnityContainer to the containing Page. This will tell Unity to inject itself into the page.
  • Use the Unity.WebForms.GetChildContainer() extension method. Anywhere on the Page, simply say Context.GetChildContainer().BuildUp(); to build up your new control/object.

Results

When running the sample web application included in the source, the default web page displayed will show the following:

Notice how the hashcode for Service1 is the same for all calls while the hashcode for Service2 changes with each invocation? This is due to the Lifetime Manager used when registering the service with the container. Service1 was registered with the Hierarchical lifetime manager, which means as long as the container is still valid, you will receive the same object instance and any child containers will maintain their own instance of the type. Service2 was declared without specifying a lifetime manager so it received the default of 'transient', or per-call, meaning every call to the container to resolve a type results in a new object.

That's it!

Tuesday, November 05, 2013

Building Unity.WebForms (Part 3 of 4)

Registering your types in the container

Now that all of the plumbing has been taken care of, we need a way to register our types so that they can be injected into our pages and controls.

When you install the Unity.WebForms NuGet package, a new folder will be added to your project called 'App_Start' with a class named UnityWebFormsStart.cs. If you have already added another NuGet package that also makes use of the WebActivator package by David Ebbo, then this folder may have already been created.

The PostStart method is tasked with creating the parent instance of the Unity container, adding it to the Application state cache, and calling the RegsiterDependencies helper method. There is no need to modify this portion of the code unless you need to do something different when initializing the container (such as when using other blocks in the Enterprise Library, in which case you would need to ensure that the container reads the configuration information from web.config).

The RegisterDependencies method is where you will register any types/services that you want to have injected into your pages, controls, and types at runtime.

Included in this source repository is a sample ASP.NET 4.0 Web Application that uses the latest Unity.WebForms NuGet package. The contents of its RegisterDependencies method is a follows:

private static void RegisterDependencies( IUnityContainer container )
{
container
// registers Service1 as '1 instance per child container' (new object for each request)
.RegisterType<Service1, Service1>( new HierarchicalLifetimeManager() )
// registers Service2 as 'new instance per resolution' (each call to resolve = new object)
.RegisterType<Service2, Service2>();
}

This uses the fluent interface (method chaining) of the container to register two types: Service1 and Service2. The registration of Service1 uses the Hierarchical Lifetime Manager to ensure that each child container gets it's own instance of the service. This is critical when using a type like an Entity Framework context to ensure that all database operations for a single user (updates and deletes in particular) are isolated from other users. The registration of Service2 doesn't define a Lifetime Manager, so it gets the default behavior of 'per-call', which means each time the container is asked for an instance of Service2 it will create a brand new object.


The last bit of magic that allows this class to be run just after the application has been started, but before requests are processed, is the assembly directive just before the namespace declaration:

[assembly: WebActivator.PostApplicationStartMethod( typeof(SampleWebApplication.App_Start.UnityWebFormsStart), "PostStart" )]

This functions very similarly to the way the UnityHttpModule module gets registered, but is using the WebActivator library that adds the ability to have multiple code classes before and after the application has been started.

Recap


Registering your types for injection has been made fairly simple, thanks to the WebActivator library. This can be made even simpler using reflection if you have an assembly that contains all of your services or are using a common interface. Either way, the most important part of registering your types for injection is to ensure you are using the proper lifetime manager for them. Some of the harder bugs I have had to track down have been because the wrong lifetime manager was used and I was either getting a new object each time (and losing state) or getting the same object every time (and getting cached/stale data).


In the last part of this series, we will tie everything together and see a working example.

Wednesday, October 16, 2013

Building Unity.WebForms (Part 2 of 4)

In part 1 of this series, I talked about building the UnityHttpModule. Now that we have this HttpModule written, we need to register it with the ASP.NET pipeline to service requests.

Registering the UnityHttpModule

Traditionally, in order to register an HttpModule with the runtime you had to make a change to the web.config file. This was potentially prone to errors if it was placed incorrectly or you put it into the configuration section for IIS 7.0+ and not in the IIS 6.0 and earlier section.

Fortunately, Microsoft added support for just this scenario in the form of assembly 'pre-start' methods with the Microsoft.Web.Infrastructure assembly.

Step 1 - Create a PreApplicationStart class

Create a new class as follows:

public class PreApplicationStart
{
    private static bool _isStarting;

    public static void PreStart()
    {
        if ( !_isStarting )
        {
            _isStarting = true;
            DynamicModuleUtility.RegisterModule( typeof( UnityHttpModule ) );
        }
    }
}

This simple class defines a static method that will get run when the application is first starting up. It uses the Microsoft.Infrastructure.DynamicModuleUtility assembly to dynamically register an IHttpModule. Presto! Adding a DLL to a project can now automatically register itself when the application is starting up... no more copy-pasta with web.config!

Step 2 - Invoking PreStart() when the application starts

The only other step required is to tell the runtime to invoke the PreStart() method when the application is starting. To do that, simply add the following to the AssemblyInfo.cs file in your project:

using System.Web;

[assembly: PreApplicationStartMethod( typeof(Unity.WebForms.PreApplicationStart), "PreStart" )]

That's it!

Recap

Registering HttpModules (or HttpHandlers for that matter) is now really easy if you use the 'pre-start' methods from the Microsoft.Web.Infrastructure in your Assembly; no more mucking with web.config!

Monday, October 14, 2013

KnockoutJS and cross-model communication

I have been playing around with shifting ASP.NET MVC view processing from the server to the client in order to lighten the load on the web server. Doing this isn't really hard, all that you really need to do is have the server render an initial view and have the client request the data it needs via AJAX (MVC) or RESTful (WebAPI) calls back to the server. That's the easy part. Processing that data on the client and turning it into a functioning application with rich interactions is the harder part.

One approach that I have taken recently is to use the KnockoutJS library. In a nutshell, Knockout allows you to create a client-side view model that can be bound to your UI components and have them kept in sync automatically for you using 'data-bind' attributes on your html elements. It has been very easy to learn and has allowed for a fairly rich end-user experience without all of the 'find control, get control value, etc.' drudgery that comes with client-side processing. Take the short, in-browser tutorial to get a feel for how easy it is to get going with this small javascript library (15kb min+gz)!

Knockout supports the ability to bind your model to only a certain portion of your UI, which makes it really easy to build partial views in MVC that encapsulate a single piece of functionality that can be reused in multiple locations within your site. One problem that quickly becomes apparent when doing this is what happens when you have a page/view composed of multiple Knockout view models and you need to communicate between them (such as making an update in one panel and having another panel update simultaneously) without tight-coupling of the view models and breaking their independence?

What I have found recently is a Knockout extension called Knockout-Postbox. This extension allows for a messaging pub/sub mechanism (similar to amplify.js and postal.js) that leverages the existing framework in Knockout but can also be used with other, non-knockout, JS code.

I recommend checking it out and playing with it a little. It looks very promising at the moment for my needs.

Wednesday, October 09, 2013

Building Unity.WebForms (Part 1 of 4)

When ASP.NET WebForms was originally produced, it's design did not lend itself to easy dependency management. Despite dependency injection being a widely considered best-practice in other Object-Oriented languages like C++ or Java (the 'D' in S.O.L.I.D. design), it was not a widely held practice within the .NET community until recently.

When ASP.NET MVC started emerging as the new kid on the block, there was a concerted effort to implement a lot of industry best practices to allow for better separation of concerns, with a cleaner, more plug-able, and more test-able interface. For a lot of developers, this was their first exposure to the various methods of Inversion of Control (Service Location and Dependency Injection). The fact that the development of ASP.NET MVC was done in the open with help from the .NET community greatly helped ensure that this was the case.

In the ASP.NET MVC ecosystem, I stumbled across a nice little library called Unity.MVC3 created by DevTrends that put together a nice approach to using the new IDependencyResolver interface introduced in MVC3 along with the Unity container from Microsoft Patterns and Practices. Since I was already using various components of the Enterprise Library, of which Unity is a part of, this was a natural fit for me.

Since ASP.NET doesn't offer a built-in mechanism for dependency management, a different approach was required. What I found through online searches was that in the ASP.NET Request Pipeline, you could intercept the Page object at the point immediately after it was created but before any Page Life-cycle methods were called. During this window, we could walk the Page control tree and have Unity resolve any properties decorated with the [Dependency] attribute (property injection).

The UnityHttpModule

Due to the state-less nature of the web and the HTTP protocol, I needed a mechanism that would allow the objects resolved by the Unity Container to be unique for each request to avoid data from one user being confused with the data from another user. Imagine how upset you would be if Amazon ended up charging you for a new 80" Plasma TV when the only item you added to your cart was a DVD

Fortunately, Unity has a mechanism for producing Child containers from a singly configured Parent container. In order for this to happen though, we need to hook into the ASP.NET request pipeline and create a new child container near the beginning of each request. Something an HttpModule is well suited for.

The module

This module is mostly a verbatim copy of the code that can be found at the MSDN Patterns &amp; Practices library.

Step 1 – Create a new HttpModule

Create a new Http Module, which is nothing more than a class that implements the System.Web.IHttpModule interface.

public class UnityHttpModule : IHttpModule
{
}

When implementing this interface, there are two methods that need to be defined: Init() and Dispose(). Since our implementation of the module will not be holding onto any unmanaged resources directly, we only need to provide an implementation of the Init() method as follows:

/// <summary>
///     Initializes a module and prepares it to handle requests.
/// </summary>
/// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, 
///     properties, and events common to all application objects within an ASP.NET application </param>
public void Init( HttpApplication context )
{
    context.BeginRequest += ContextOnBeginRequest;
    context.PreRequestHandlerExecute += OnPreRequestHandlerExecute;
    context.EndRequest += ContextOnEndRequest;
}

This method is short and focused, registering the module to handle three different events:

  • BeginRequest - Creates a new child container from the parent container.
  • PreRequestHandlerExecute - This event occurs before the ASP.NET runtime starts executing an event handler, like a Page or a Web Service.
  • EndRequest - Disposes of the child container to ensure resources are properly garbage collected.

Step 2 - Create the child container for the request

The OnBeginRequest method simply creates a new child container from the parent container so that each web request gets it's own instances of the registered types.

private void ContextOnBeginRequest( object sender, EventArgs e )
{
    ChildContainer = ParentContainer.CreateChildContainer();
}

where the ParentContainer and ChildContainer properties are defined as follows:

private IUnityContainer _parentContainer;

private IUnityContainer ParentContainer
{
    get { return _parentContainer ?? ( _parentContainer = HttpContext.Current.Application.GetContainer() ); }
}

private IUnityContainer _childContainer;

private IUnityContainer ChildContainer
{
    get { return _childContainer; }

    set
    {
        _childContainer = value;
        HttpContext.Current.SetChildContainer( value );
    }
}

More information about child container usage in Unity can be found here: Using Container Hierarchies.

Step 3 - Determine if this is a request that needs to built up

The OnPreRequestHandlerExecute event handler is fired just prior to the request being handled by the ASP.NET runtime and is defined as follows:

private void OnPreRequestHandlerExecute(object sender, EventArgs e)
{
    /* static content; no need for a container */
    if ( HttpContext.Current.Handler == null )
    {
        return;
    }

    var handler = HttpContext.Current.Handler;
    ChildContainer.BuildUp( handler.GetType(), handler );

    // User controls are ready to be built up after the page initialization in complete
    var page = handler as Page;
    if ( page != null )
    {
        page.InitComplete += OnPageInitComplete;
    }
}

First, we need to check if the current request is for a static resource (in which case the Http Context Handler will be null) or something that the ASP.NET runtime would be involved with handling. If this is a request that will be handled by ASP.NET, then we get an instance of the child container, have it build-up the current HTTP handler, and register an event handler for the page InitComplete event.

Step 4 - Build up the control tree

The page InitComplete event is raised immediately after the page object has been instantiated, but prior to the page life-cycle events being raised. At this point, we have a chance to perform property injection on the page and any nested controls. The body of the OnPageInitComplete event handler is defined as follows:

private void OnPageInitComplete( object sender, EventArgs e )
{
    var page = (Page)sender;

    foreach ( Control c in GetControlTree( page ) )
    {
        var typeFullName = c.GetType().FullName ?? string.Empty;
        var baseTypeFullName = c.GetType().BaseType != null ? c.GetType().BaseType.FullName : string.Empty;

        // filter on namespace prefix to avoid attempts to build up system controls
        if ( !typeFullName.StartsWith( "System" ) || !baseTypeFullName.StartsWith( "System" ) )
        {
            ChildContainer.BuildUp( c.GetType(), c );
        }
    }
}

Here we walk the control tree for the page and have the child container build up each control. In order to prevent a lot of potential reflection overhead for controls that have not been authored by you, we limit the build up action to only controls that are not defined in the System.*namespaces. This could be further optimized in your own project by only looking for namespaces that you control, but in order to make this into a universal NuGet package that others could use, I simply took the route of filtering out the System namespace.

The GetControlTree() method (shown below) is just a wrapper around recursively walking the control tree.

private static IEnumerable GetControlTree( Control root )
{
    if ( root.HasControls() )
    {
        foreach ( Control child in root.Controls )
        {
            yield return child;

            if ( child.HasControls() )
            {
                foreach ( Control c in GetControlTree( child ) )
                {
                    yield return c;
                }
            }
        }
    }
}

Step 5 - Clean-up

The ContextOnEndReqesut method gets called at the tail-end of the request pipeline and allows us to properly dispose of the child container, which in turn disposes of all objects registered in the container.

private void ContextOnEndRequest( object sender, EventArgs e )
{
    if ( ChildContainer != null )
    {
        ChildContainer.Dispose();
    }
}

Recap

In this post, we saw how to create an HTTP Handler that will intercept the constructed Page/Control just before any life-cycle events are fired allowing us to inject any dependencies from our container (Unity).

In the next post, we will see how to register this new Handler into the request pipeline without having to edit the web.config file.

Wednesday, January 18, 2012

Using a Global AssemblyInfo File

I’ve been meaning to post this for a long time, but for some reason it always seems to fall off the radar. Not anymore…

For all but the most trivial applications, you will most likely separate your solution into multiple projects that each have their own responsibility. This allows for better code re-use and better separation of concerns.

An issue that you might end up facing is that each project contains it’s own AssemblyInfo.cs file and several of the assembly directives in these have values that are repeated. For instance:

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany( "KyKoSoft" )]
[assembly: AssemblyProduct( "KyKoSoft Application Foo" )]
[assembly: AssemblyCopyright( "COPYRIGHT © 2012 KyKoSoft.  All Rights Reserved." )]
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "en-US" )]

The values for AssemblyCompany, AssemblyProduct, AssemblyCopyright, etc. will most likely have the exact same values for each project in the solution. Would you want to manually update the AssemblyCopyright setting in each project on January 1st every year? What if your company is bought out or your product gets renamed?


In order to keep things DRY (Don’t Repeat Yourself) and make updates easier, a real simple solution is to extract the repeated/common values into a new file (say GlobalAssemblyInfo.cs) located at the root of your solution. Then, right-click each project and select Add | Existing Item… and navigate to the root of your solution and select the GlobalAssemblyInfo.cs file.


But wait! Instead of just clicking the Add button (or double clicking on the file), use the little down arrow on the Add button and select the Add As Link option. This will ‘link’ the file into the project instead of copying it into the project directory (remember, we want to maintain this information only once).


If you tried to compile the project at this point, you will get a compilation error stating that there were duplicate Assembly directives defined. This is because your original AssemblyInfo.cs file (located in the Properties folder) still has these directives in it. Simply open it up and remove the duplicated (global) entries and recompile.


Presto! No more duplication!

Tuesday, February 08, 2011

MonoDroid Licensing

I have been playing around with MonoDroid for the past few weeks, mostly keeping an eye on how the betas have been progressing. I am very intrigued by the fact that I can use my normal development tools and language (Visual Studio 2010 & C#), even re-use existing libraries, to create a application that runs on Android.

However, while monitoring the mailing lists someone posed the question of licensing costs for MonoDroid once it reaches 1.0. Being that Mono is an open source project, I had assumed that there wouldn’t be a licensing cost… wrong. According the to the MonoDroid FAQ, while licensing hasn’t been finalized yet it will most likely follow a similar structure to MonoTouch (iOS version of Mono) and cost about $400 USD for an individual user and $1,000 USD for enterprise users.

Sorry, but as an individual user $400 USD seems a little steep for any small applications to be built using it. Even if I get 400 people to use my app and I only charge $0.99, I still won’t break even unless the application is a huge success. Then again, since C# and Java are so similar and Eclipse and the Android SDK are free, I could write core logic for the application in C# as a Web Service and then just building the UI in Java with Eclipse. No $400 USD entrance fee needed.

Would have been nice though… a WPF, Silverlight/Windows Phone 7, MVC, and Android app… all from the (mostly) same code base. Alas.

Saturday, January 22, 2011

Upcoming Silverlight Firestarter Events

Jim O’Neil, Northeast Developer Evangelist for Microsoft, recently blogged about the upcoming Silverlight Firestarter series. It just so happens that I have been investigating using Silverlight 4 for an upcoming project re-write and there just happens to be an event date here in Rochester! What Luck!

You can get the details at Jim’s blog (http://blogs.msdn.com/b/jimoneil/archive/2010/12/23/firestarter-silverlight-for-windows-7.aspx) and follow the link there to register for yourself!

Hope to see you there!

Wednesday, January 12, 2011

Moving a TFS Source Controlled Project

Recently, I needed to reorganize the folder that contained all of the projects under source control for a solution. The solution was started several years ago and the number of projects has steadily grown over the years and started polluting the root solution directory. I wanted to clean this up and move projects into sub-folders for their functional area, such as plug-ins, data/business, and common.

This seemed like a fairly trivial thing to do, but I quickly ran into problems. Most of these problems seemed to be related to the fact that the projects were under source control with TFS. After some trial an error, I came up with the following process:

  • Load the solution that contains the projects that are moving.
  • Remove the Source Control Bindings for any of the projects that are going to move. This can be accomplished by going to File > Source Control > Change Source Control. In the resulting window, select the projects that are going to move and click the “Unbind” button in the toolbar. This will update the solution file.
  • Close the solution.
  • Open the Source Control Explorer and navigate to the parent folder that contains the project to be moved.
  • Right-click on the project folder and select “Move…”. In the resulting window, browse to the new location for the project.
  • Navigate into the new project file location and checkout the “{projectName}.vspscc” file. If you don’t do this now, you will receive an error when you re-add the source control bindings later.
  • Close Visual Studio.
  • Using Windows Explorer, navigate to the root folder for the solution and delete the “{solutionName}.suo” file. This prevents Visual Studio from getting confused the next time you open the solution.
  • Edit the “{solutionName}.sln” file and update the path to the new project file location. Just search for the project name and the update the portion of the line the points to the “*.*proj” file.
  • Open the solution. At this point, any projects that reference the moved projects will be updated (checked out) to reflect the new location.
  • Update the Source Control Bindings to rebind the projects that were removed at the beginning of the process (the unbound projects will be located at the bottom of the list) by selecting the project and clicking the “bind” button in the toolbar.
  • At this point, the project will be highlighted with a red underline stating that there is an issue. This is because we haven’t checked our changes in yet so the server path doesn’t exist. This will be corrected soon.
  • Rebuild your solution to make sure there are no side-effects. When I did this, I had to update a few references to shared DLL’s in the moved projects because the reference path was no longer valid.
  • Commit your changes.

That’s it. Simple, right? ;)

There are some things you could do differently. For instance, instead of editing the solution file by hand, you could remove the project from the solution, perform the TFS move, then re-add the project to the solution. However, you will need to re-add the reference to the moved project in any projects that depended on it originally. For me, it was faster to just edit the solution file manually because this doesn’t remove project references and Visual Studio will update the dependant projects for me.

Happy Coding!

Thursday, November 05, 2009

Visual Studio Team System and Cloak

When I first started using Visual Studio with TFS for a new position, I started reading the Team Development with Visual Studio Team Foundation Server guide since I had never used it before. I got about half-way though it before I started the new job and became so busy I no longer had time to finish reading it. Had I kept reading, I would have found a piece that talked about the “cloak” menu item when viewing your Source in the Source Control Explorer.

Say you have a root-level folder in Source Control with the following structure…

  • ProjectA
    • MainLine
  • Branches
    • v1.0
    • v1.0-SP1
    • v2.0

Rather than create a separate workspace mapping for each version, you would create a single workspace at the top level. This makes it easy to keep everything in sync by just performing a Get Latest operation on the ProjectA node and you will instantly have the latest for everything.

There are a couple of problems with the approach. First, what if you are currently only working on the MainLine version? Do you really want the previous 3 versions stored on your disk? If the project is small this might not add up to much, but if it’s a major project this can easily consume tens of gigabytes of space.

The second problem comes into play when performing a Get Latest operation. With everything mapped from the root-level node, TFS needs to contact the server and compare your workspace with the server in order to determine what has changed and what needs to be updated. If you are currently working only on the MainLine branch, do you want or care about the changes in another branch? (Veteran coders will know that you can perform a Get Latest on specific folders, but this sometimes leads to performing a Get Latest too low in the tree and missing required dependency updates from higher up).

The solution is to create a root-level workspace mapping as stated above. When you are prompted to perform a Get Latest, say no. In the Source Control Explorer window, right-click on any folder you don’t want included and select the Cloak menu item. This prevents the folder from being included in your workspace mapping and prevents it from being downloaded and subsequently updated every time you perform a Get Latest.

In our example, someone only working on the MainLine branch would cloak the Branches folder. If someone needs to be working on the MainLine as well as a previous version (like a Service Pack), they could cloak the individual branch folders they don’t care about.

Nice!

Monday, June 01, 2009

Vista gets a bad rap

Recently, I was ‘forced’ to upgrade one of my development machines to Vista in order to start playing with the Windows Azure cloud tools due to the requirement of IIS 7. While I’m not sure how valuable publishing enterprise applications in the cloud are going to be, it is a good option for small to medium sized and/or and resource-(con)strained businesses.

So, with a bit of hesitation, I decided to wipe my machine and take the Vista plunge full on and installed Vista x64 SP1. I had some issues using the latest video driver provided by Dell that would not allow me to run the ‘Aero’ theme (by limiting my color depth to 16-bit instead of 32-bit), but once I rolled that back to an earlier version everything was running smoothly.

After a couple of weeks running Vista with all of my development tools and applications installed, I have to say that although there is a bit of a learning curve when you are very accustomed to XP, I haven’t run into any real issues yet. In fact, the machine is running faster than 32-bit XP and has actually been fun to use.

Caveat: My machine (a Dell Latitude D830) has an Intel Core 2 Duo CPU T7700 @ 2.4GHz, 4GB RAM, reasonably fast hard drive, and a middle-tier graphics card, so it is definitely Vista capable and scores a Windows Experience Index of 3.4 (limited by the graphics card; all other stats are 4.8+)

I cannot speak of the experience running Vista x32, but I do know that when Microsoft wrote the x64 versions of Windows they were able to eliminate a lot of the previous pain points simply because of the new architecture.

Based on my experiences so far, I wouldn’t mind moving some of my other (capable machines) over to Vista. However, I might just wait for Windows 7 to be released. I know a few people that are currently running it and have nothing but good things to say about it. Time will tell.

Monday, May 25, 2009

Learning Silverlight

I’ve been very interested in Silverlight since it’s introduction (and more importantly XAML), but have never really had the time to invest in learning it until now.

Recently I’ve been performing a technical evaluation for an upcoming project and Silverlight is one of the proposed technologies that could be used. Naturally I started Googling around the web for some learning resources and stumbled across (yet another) series of videos by Mike Taulty posted on Microsoft’s Channel 9 website entitled “44 Amazing Silverlight 2.0 Screencasts”.

These short (usually under 10 minutes) screencasts are each focused on a particular aspect of Silverlight and start from the very basic and progressively build to more complex topics. Mike has a very easy-going approach to explaining the topic and makes (purposefully) makes mistakes along the way to show you some of the common pitfalls/issues that you could encounter along the way.

If you are at all interested in Silverlight (and I think you should be), I would highly recommend this video series as one of your first stops along the way.

Monday, May 18, 2009

Preparing for Visual Studio 2010 and .NET 4.0

While poking around Microsoft’s Channel 9 website, I stumbled across a series of videos dubbed “10-4”. Those of you that have had your morning coffee have probably already guessed that these videos are about Visual Studio 2010 (also referred to on the net as VSX) and the .NET 4.0 Framework. These videos are quick (less than 20 minutes) that highlight what is new or changed from previous versions.

I’ve watched about half of them so far and they have been helpful in identifying new technologies to incorporate into new or existing applications.

Give them a go on your lunch break or whenever you need a break from your current coding headache!

Wednesday, April 08, 2009

Upcoming "Code Analysis, Metrics, and Style" Presentation

I will be giving a presentation entitled "Code Analysis, Metrics, and Style" at the end of the month to the Visual Developers of Upstate New York (VDUNY) user group, which meets once a month at Microsoft's office in Rochester, NY. The presentation, divided into 3 parts as the title suggests, will focus on using several tools available to developers to help them write better quality code.

The 'Code Analysis' section will highlight using the built-in 'Code Analysis' tools available in Visual Studio Team Editions as well as FxCop, which is the foundation for the built-in Code Analysis engine. These tools analyze the compile IL code and look for common programming errors.

The second section talks about using the Code Metric tools (again, available in the Visual Studio Team Editions) to determine the maintainability, complexity, and dependencies of your code. Using these metrics will help you determine what areas of the code you should focus on in order to make the software easier to maintain.

The last section will focus on using Microsoft's Source Analysis add-on for Visual Studio (StyleCop). In contrast to Code Analysis, Source Analysis analyzes your actual source code looking for style issues, such as all files need to have a copyright header, braces should be on new lines, methods should have doc comments, etc. While this may not seem that important, it can help enforce a common style for your entire codebase making it easier for others to get up to speed with your code.

Hope to see you there.