Blog Posts

  • Selectively resolving services at runtime with Autofac

    This article explains how to selectively resolve a service at runtime with Autofac by making use of the IEnumerable<Lazy<IExport, IExportMetadata>> and Lazy<T, TMetadata> relationship types. It also provides an example of how to refactor the controller constructor to receive the list of exports and how to query the metadata to select the correct export service at runtime.

  • Two simple tips for working with LINQ and IEnumerable<T>

    This article provides two tips for working with LINQ and IEnumerable<T>: use Any() instead of Count() to check for non-empty return values, and use Enumerable.Empty<T> and never return null.

  • Worst validation message ever

    A web service validation message was found to be difficult to understand due to its extremely technical and legal-like wording.

  • Autofac ASP.NET MVC 4 (Beta) Integration

    Autofac 2.6.1 has released a MVC 4 Beta integration, available for download via NuGet, with no breaking changes from the MVC 3 version. The minor change made in the internals allows the lifetime scope applied to a registration to be shared between MVC and the Web API. Users should report any bugs on the issue tracker or ask questions on Stack Overflow using the “autofac” tag.

  • Autofac ASP.NET Web API (Beta) Integration

    Autofac has released a beta version of the ASP.NET Web API integration package for NuGet, which supports both web hosting and self hosting scenarios. The integration allows for services to be registered per API controller invocation. A HTTP module style implementation is not required due to the IHttpControllerFactory interface allowing for an abstraction between the two hosting modes. The implementation details are discussed in the article.