Nothing earth shattering here - but was wrestling with current WCF services and trying to leverage the delicious newness of the WebApi with Ninject 3.0. A bit of pain and a few tears later...
1: public class MvcApplication : NinjectHttpApplication
2: {
3: /// <summary>
4: /// Called when [application started].
5: /// </summary>
6: protected override void OnApplicationStarted()
7: {
8: base.OnApplicationStarted();
9:
10: AreaRegistration.RegisterAllAreas();
11: FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
12: RouteConfig.RegisterRoutes(RouteTable.Routes);
13: BundleConfig.RegisterBundles(BundleTable.Bundles);
14: }
15:
16: /// <summary>
17: /// Creates the kernel.
18: /// </summary>
19: /// <returns>IoC container object</returns>
20: protected override IKernel CreateKernel()
21: {
22: IKernel kernel = new StandardKernel(new NinjectSettings { LoadExtensions = true });
23:
24: // add AutoMapper to the core -> needs to be first; as services will use this.
25: kernel.Bind<ITypeMapFactory>().To<TypeMapFactory>();
26: kernel.Bind<ConfigurationStore>().ToConstant(new ConfigurationStore(kernel.Get<ITypeMapFactory>(), MapperRegistry.AllMappers())).InSingletonScope();
27: kernel.Bind<IConfiguration>().ToMethod(c => c.Kernel.Get<ConfigurationStore>());
28: kernel.Bind<IConfigurationProvider>().ToMethod(c => c.Kernel.Get<ConfigurationStore>());
29: kernel.Bind<IMappingEngine>().To<MappingEngine>();
30:
31: kernel.Bind(
32: x =>
33: x.FromAssembliesMatching(new[]
34: {
35: "*.Service.dll", "*.Service.Mvc.dll", "*.Service.Data.dll"
36: }).SelectAllClasses().BindAllInterfaces());
37: kernel.Bind<ServiceHost>().To<NinjectServiceHost>();
38:
39: // not intended to be used when deriving from NinjectHttpApplication <sigh>
40: ////kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
41: ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(kernel));
42: var locator = new NinjectServiceLocator(kernel);
43: ServiceLocator.SetLocatorProvider(() => locator);
44: return kernel;
45: }
46: }