Created
June 4, 2012 20:44
-
-
Save andreasohlund/2870765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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