Tuesday, February 24, 2009

An evening of mockery at Skills Matter on the 23 of March

Abid Quereshi and I will be talking about mocking frameworks at Skills Matter on the 23 March. The details are here.

Abid's going to be talking about Moq:

"Introduction to Moq: Pronounced "Mock-You", Moq is a simple yet powerful .NET Mocking library. Moq makes use of .NET lambda expressions, reducing the amount of test code you will need to write. This presentation will demonstrate Moq and highlight some main differences with other mock object frameworks."

I will cover Rhino Mocks, especially looking at the new 3.5 features and also taking a look at Automocking. It should be a great evening.

Monday, February 16, 2009

WCF / Windsor Integration: Using the perWebRequest lifestyle

I briefly introduced Windsor WCF Integration a while back. I've been using it successfully in one of my current projects, but we had an issue recently with enabling the 'perWebRequest' lifestyle. Our project also uses the Windsor NHibernate Facility which automatically provides 'session per request' that we wanted to reuse with our WCF services. Both require a reference to the current HttpContext, but by default WCF does not integrate with the ASP.NET pipeline. This is by design, because it is intended that you should be able to host your WCF service with diverse protocols/hosts, not just HTTP/IIS/ASP.NET. But if you are simply using WCF to host services alongside an existing ASP.NET application and you want to reuse the same Windsor configuration for both it would be useful if WCF could gain access to the ASP.NET pipeline.

And voila! There is indeed a way of configuring WCF to integrate, simply set the serviceHostingEnvironment aspNetCompatibilityEnabled property to 'true' like this:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

You also need attribute your service class to require/allow integration:

    RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyService : IMyContract

Now HttpContext.Current returns the current HttpContext as expected and both the 'perWebRequest' lifestyle and the NHibernate Facility work as expected. It also means that your service can participate in your application's security settings, session state and impersonation if that's what floats your boat. Of course it doesn't help you if you want to host your service outside of IIS. In that case you'd probably want to either implement your own custom lifestyle that works with the OperationContext (WCF's equivalent to HttpContext) or implement an IEndpointBehavior. There's an example of how to do the latter in the WCF Facility's unit tests. Check out the UnitOfworkEndPointBehavior class.

More detail on the ASP.NET compatibility settings can be found in this excellent blog post by Wenlong Dong.

Friday, February 06, 2009

VBug London 10th Feb: Why to I need an Inversion of Control Container?

I'm going to be giving my IoC container talk at VBug London next Tuesday (10th February). It's going to be at Anteo Group, 8-9 Hayne Street, London, EC1A 9HH (see map below). Arrive at 6.30pm for a 7pm start. It's being organised by Sam Morrison who assures me that there will be plenty of time for socialising after the talk.


View Larger Map