Ninject working with WCF Web API Preview 5

后端 未结 3 1771
我寻月下人不归
我寻月下人不归 2021-01-04 23:18

Can anybody point me in the right direction to get Ninject working with WCF Web API Preview 5? I have it successfully up and running in my ASP.NET MVC 3 project and also in

3条回答
  •  执念已碎
    2021-01-04 23:46

    There are great answers to the question here but I would like to show you the way with default WebApi configuration:

        protected void Application_Start(object sender, EventArgs e) {
    
            RouteTable.Routes.SetDefaultHttpConfiguration(new Microsoft.ApplicationServer.Http.WebApiConfiguration() { 
                CreateInstance = (serviceType, context, request) => GetKernel().Get(serviceType)
            });
    
            RouteTable.Routes.MapServiceRoute("Api/People");
        }
    
        private IKernel GetKernel() { 
    
            IKernel kernel = new StandardKernel();
    
            kernel.Bind().
                To();
    
            return kernel;
        }
    

    The below blog post talks a little bit about Ninject integration on WCF Web API:

    http://www.tugberkugurlu.com/archive/introduction-to-wcf-web-api-new-rest-face-ofnet

提交回复
热议问题