WSCF.blue on endpoint.tv

by Alex Meyer-Gleaves 11 November 2010 - 4:02 PM

If you are interested in a quick introduction to WCF contract first make sure you check out the latest episode of endpoint.tv. Ron Jacobs has recorded a Trans-Atlantic webcast with WSCF.blue developer Santosh Benjamin.

Get Microsoft Silverlight

Great stuff Benjy!

Tags: ,

WSCF | Web Services

Random links for October 2010

by Alex Meyer-Gleaves 8 November 2010 - 2:04 PM

Here are a few links that I found interesting for one reason or another.

  • Phono - jQuery Phone Plugin
    Phono is a simple jQuery plugin and JavaScript library that turns any web browser into a phone; capable of making phone calls and sending instant messages. You can even connect to SIP clients; all with a simple unified API.
  • re-linq
    With re-linq, it's now easier than ever to create full-featured LINQ providers. Instead of the IQueryable expression tree, re-linq gives you an abstract syntax tree that resembles the original LINQ query expression.
  • Readmeo - Read your links later
    So much to read, so little time? Readmeo is a simple tool that allows you to save links for reading later.
  • Fillerati - Faux Latin is a Dead Language
    I made Fillerati because I grew tired of reading "Lorem ipsum..." on every new design I was working on. It's built with HTML5 and CSS2/CSS3, and consequently is best viewed in a modern browser such as Chrome, Firefox, Safari or Opera.
  • HubbleDotNet - Free open-source SQL full-text search database can be used as search engine
    HubbleDotNet is an free open-source full-text search database project based on .Net Framework which can be used as search engine system. Fast, precise, SQL supported, distributable and easy to use.
  • Elastic CSS Framework
    A simple css framework to layout web-based interfaces, based on the printed layout techniques of 4 columns but with capabilities to unlimited column combinations. and capacity to make elastic, fixed and liquid layout easily.
  • Code Flow 49: Automatic INotifyPropertyChanged with DynamicObject
    In this post, I show how to use the DynamicObject class introduced in .Net 4 to create a proxy that wraps access to another object’s properties while adding automatic support for INotifyPropertyChanged.
  • Extension Method
    ExtensionMethod.NET is a database of C# 3.0, F# and Visual Basic 2008 extension methods. It contains many user-rated extension methods that will expand your code library immediately.
  • HTML5 enabling script
    Since HTML5 is getting more attention by way of marking up our new pages, and the only way to get IE to acknowledge the new elements, such as
    , is to use the HTML5 shiv, I've quickly put together a mini script that enables all the new elements.
  • #eCSStender.org { content: "Homepage"; }
    Say goodbye to the browser-specific properties and hacks cluttering your files and say hello to lean, mean CSS. With eCSStender, when you write the rules, browsers pay attention.
  • GalaSoft - MVVM Light Toolkit
    The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in WPF, Silverlight and in the Windows Phone 7.
  • NBuilder - Rapid generation of test objects for .NET
    Through a fluent, extensible interface, NBuilder allows you to rapidly create test data, automatically assigning values to properties and public fields that are of type of the built in .NET data types (e.g. ints and strings).
  • Fluent Assertions
    Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test.
  • fit-PC2
    fit-PC2 is smaller than a soft drink can. In fact, it is the smallest PC available. fit-PC2 is not only tiny, but also fanless. fit-PC2 fits anywhere and saves significant space.
  • Tumblr
    Tumblr lets you effortlessly share anything. Post text, photos, quotes, links, music, and videos, from your browser, phone, desktop, email, or wherever you happen to be. You can customize everything, from colors, to your theme's HTML.
  • NBehave
    he primary goal of NBehave is a framework for defining and executing application requirement goals. These characterizations are modeled after the Behavioral Driven Design (BDD) terms Story, Scenario, Given, When, Then.
  • 7 Freely available E-Books/Guides I found essential for .NET Programmers and Architects : Amazedsaint's .net journal
    Some of these books will definitely help us to evolve our coding skills and thought processes for developing better solutions.
  • OpenRasta
    OpenRasta is a resource-oriented framework for .NET enabling easy ReST-ful development of web sites and services.
  • NuPack
    NuPack is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development.
  • Kylo Browser
    Kylo is a Mozilla-based web browser optimized for surfing the web on your HDTV from the comfort of your couch.
  • NoSQL Basics, Benefits and Best-Fit Scenarios
    A popular new movement aims to take SQL database management systems out of the stack. But when is this emerging approach right for you?
  • visualizing.org
    Making sense of complex issues through data and design.
  • Sass - Syntactically Awesome Stylesheets
    Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
  • Snipt | Share and store code or command snippets.
    It's good for storing small pieces of code or commands that you use rather frequently, and will probably forget.
  • atomsite.net-The AtomPub server for .NET
    AtomSite is a standards-based web publishing system. It's free, open and built using Microsoft's latest web framework. It'll have your website up in a snap!
  • FluidKit
    This is a WPF library containing a powerhouse of controls, frameworks, helpers, tools, etc. for productive WPF development.
  • Jo HTML5 Mobile App Framework
    A Pretty UI Widget Framework With a side of DOM, event and data stuff.
  • tipsy
    Tipsy is a jQuery plugin for creating a Facebook-like tooltips effect based on an anchor tag's title attribute.
  • AgileZen – Project management gets lean
    AgileZen is a simple, flexible, and cost-effective way to manage your work. With an easy-to-use web interface, and by drawing on ideas from lean manufacturing, we help you stay organized, focused, and on target.
  • Instant CSS Code - Create a web project framework in seconds.
    Instant CSS Code allows you to quickly create a web project framework with valid HTML/xHTML and CSS in only a matter of seconds, allowing you to get your project up and running faster!
  • Window Functions (OVER Clause) – Help Make a Difference - Puzzled By T-SQL
    In this article I will explain some of the key features that are missing in SQL Server and why it’s important to add support for such features.
  • ProtoFluid - HTML5 and CSS3 Web App Prototyping
    Quick, easy web app testing in portrait/landscape on any screen size via CSS Media Queries.
  • .NET Micro Framework - Home
    The .NET Micro Framework is .NET for small and resource constrained devices. It offers a complete and innovative development and execution environment that brings the productivity of modern computing tools to this class of devices.
  • googlechartsharp - Project Hosting on Google Code
    A C# wrapper for the Google Chart API.
  • Google URL Shortener
    All goo.gl URLs and click analytics are public and can be shared by anyone.
  • Extended Reflection - Microsoft Research
    ExtendedReflection makes it easy to build runtime analysis tools for .NET. ExtendedReflection takes care of instrumenting MSIL bodies at runtime and exposes more than 200 .NET callbacks, such as method enter/exit, argument values or field writes.
  • Eloquera DB | Home
    Eloquera Database is an object database for .NET environments. It has several unique features which make it highly attractive to web and desktop application developers.
  • STSdb - STS Soft Database - STS Soft Home Page
    STSdb is a free open-source embedded object database system (NoSQL key/value pair storage engine) designed for mission critical and real-time applications. It provides intuitive use and blazing performance.
  • Sterling Isolated Storage Database with LINQ for Silverlight and Windows Phone 7
    Sterling is a lightweight object-oriented database implementation for Silverlight and Windows Phone 7 that works with your existing class structures.
  • toto
    toto is a git-powered, minimalist blog engine for the hackers of Oz. The engine weighs around ~300 sloc at its worse.
  • LESS - Leaner CSS
    LESS extends CSS with: variables, mixins, operations and nested rules.
  • Mond-JN - jQuery UI - Effects cheat sheet
    blind, clip, drop, explode, fold, puff, slide, scale - pattern1, scale - pattern2, scale - pattern3, pulsate, bounce, highlight, shake, and transfer.

Tags:

Random

ASP.NET MVC 3 Beta integration for Autofac

by Alex Meyer-Gleaves 4 November 2010 - 7:38 PM

I have just checked into trunk a first pass at the ASP.NET MVC 3 Beta integration for Autofac. In hope of simplifying the requirements for those getting started with the integration I wanted to prevent the need to:

The code below is an example of all you would need to put into the application start event to get up and running.

ContainerBuilder builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.Register(c => new Logger()).As<ILogger>().InstancePerHttpRequest();

IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

The core piece of the integration is the AutofacDependencyResolver. This is an implementation of the IDependencyResolver interface that Brad Wilson outlines in his blog post series on ASP.NET MVC 3 Service Location. The interface requires you to implement two simple methods: GetService and GetServices. When no service is found GetService should return null, and GetServices should return an empty IEnumerable<object>. The implementation of these methods ends up being straight forward (ignoring for now the code related to managing the CurrentLifetimeScope).

public object GetService(Type serviceType)
{
    return CurrentLifetimeScope.IsRegistered(serviceType) ? CurrentLifetimeScope.Resolve(serviceType) : null;
}

public IEnumerable<object> GetServices(Type serviceType)
{
    Type enumerableServiceType = typeof(IEnumerable<>).MakeGenericType(serviceType);
    object instance = CurrentLifetimeScope.Resolve(enumerableServiceType);
    return ((IEnumerable)instance).Cast<object>();
}

When MVC needs to create a controller it will ask the DependencyResolver for an instance. The AutofacDependencyResolver returns the controllers that are registered in the container it was provided. These are usually registered using the RegisterControllers method on the ContainerBuilder as shown in the first code sample. There is no longer a need to create a class that derives from the DefaultControllerFactory for the sole purpose of returning controller instances. This means the AutofacControllerFactory is no longer required and has been removed.

The Autofac MVC integration has always supported the concept of a HTTP request lifetime scope. This means that the lifetime of a service can be scoped to the current HTTP request. The ILogger service registration in the sample code above uses the InstancePerHttpRequest method to indicate that the same instance of the logger service should be used for all dependency resolutions that occur during the current HTTP request. To make sure that the nested lifetime scope that Autofac creates for each request is disposed, it needs to be notified when the request has ended.

The only reliable way to do this is to create a HTTP module that subscribes to the EndRequest event of the HttpApplication. To register a HTTP module you need to add an entry to the web configuration file, which is something that I was hoping to avoid. Rick Strahl outlines one way of achieving programmatic registration of a module in his Dynamically hooking up HttpModules post, but for the integration this would require the user to manually add the code to their HttpApplication instance (by default called MvcApplication).

It turns out that there is in fact another way to programmatically register a module. The Microsoft.Web.Infrastructure.dll assembly that ships with the ASP.NET Web Pages installer (AspNetWebPages.msi) contains a rather helpful class called DynamicModuleUtility. It has a single method called RegisterModule that accepts a Type for the module to register. You can only call this helper from a method that is marked as pre application start code as defined by the PreApplicationStartMethodAttribute applied to an assembly. The same trick is used in System.Web.Pages.dll to register the new WebPageHttpModule. Phil Haack has a blog post that talks about the PreApplicationStartMethodAttribute and some other interesting new ASP.NET 4 features in greater detail if you are keen to know more. You need to install ASP.NET Web Pages before installing ASP.NET MVC 3 so we know the assembly with this helpful little gem will be available.

In the Autofac integration we first needed to add the assembly attribute.

[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), "Start")]

This points to a static class that contains a single static method called Start. Inside this method we call the DynamicModuleUtility to register the RequestLifetimeModule that will informs us when the HTTP request has ended. There is no need to ever call this class directly but unfortunately, it and the method must be public. That is why we have the EditorBrowsable attribute being applied in order to hide the class from the editor. Not really that much work to save a user from having to dive into the web configuration file.

[EditorBrowsable(EditorBrowsableState.Never)]
public static class PreApplicationStartCode
{
    private static bool _startWasCalled;

    public static void Start()
    {
        if (_startWasCalled) return;

        _startWasCalled = true;
        DynamicModuleUtility.RegisterModule(typeof(RequestLifetimeModule));
    }
}

There is a new interface in the MVC 3 integration called ILifetimeScopeProvider. The HTTP module RequestLifetimeModule shown above actually implements this interface and is the default implementation used by the AutofacDependencyResolver. You can see from the AutofacDependencyResolver code shown at the start of the post that the resolutions are happening from the CurrentLifetimeScope property.

internal ILifetimeScope CurrentLifetimeScope
{
    get
    {
        if (_lifetimeScopeProvider == null)
            _lifetimeScopeProvider = GetRequestLifetimeModule();
        return _lifetimeScopeProvider.GetLifetimeScope(_container, _configurationAction);
    }
}

You can add your own ILifetimeScopeProvider implementation to the container that is passed to the AutofacDependencyResolver if you want to replace the HTTP request based lifetime behaviour. The AutofacDependencyResolver will attempt to retrieve it from the container during its constructor. Because the RequestLifetimeModule is the default ILifetimeScopeProvider and an instance was already created by ASP.NET when the module was initialised, we can go and grab that from the HttpModuleCollection of the current HttpApplication.

static ILifetimeScopeProvider GetRequestLifetimeModule()
{
    HttpModuleCollection httpModules = HttpContext.Current.ApplicationInstance.Modules;
    for (int index = 0; index < httpModules.Count; index++)
    {
        if (httpModules[index] is RequestLifetimeModule)
            return (RequestLifetimeModule)httpModules[index];
    }
    throw new InvalidOperationException(string.Format(
        AutofacDependencyResolverResources.HttpModuleNotLoaded, typeof(RequestLifetimeModule)));
}

None of the model binding code has been moved into the new integration yet. I am hoping that this can be refactored to use the new IModelBinderProvider interface. This is only a first pass based on a new approach so it is likely that some of this will change. I have certainly found the exercise interesting enough that I thought it was worth sharing the start of the journey.

Tags: ,

Autofac | Web Development

About the author

Alex Meyer-Gleaves I'm a Technical Architect living in Australia (that island like continent in the southern hemisphere). I love Microsoft .NET and C#. I hate early mornings, slow drivers and Lotus Notes.

Twitter

Google Shared

 

Month List

Recent Comments

Comment RSS

Links

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010