Skip to content

Instantly share code, notes, and snippets.

@andreasohlund
Created June 4, 2012 20:44
Show Gist options
  • Select an option

  • Save andreasohlund/2870765 to your computer and use it in GitHub Desktop.

Select an option

Save andreasohlund/2870765 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using NServiceBus;
public static class ConfigureWeAPiDependencyInjection
{
public static Configure ForWebApi(this Configure configure)
{
// Find every controller class so that we can register it
var controllers = Configure.TypesToScan
.Where(t => typeof(ApiController).IsAssignableFrom(t));
// Register each controller class with the NServiceBus container
foreach (Type type in controllers)
configure.Configurer.ConfigureComponent(type, DependencyLifecycle.InstancePerCall);
// Set the MVC dependency resolver to use our resolver
GlobalConfiguration.Configuration.DependencyResolver =
new NServiceBusDependencyResolverAdapter(configure.Builder);
return configure;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment