Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue using ASP.Net MVC 4 Web API with Ninject.Web.WebApi
    primarykey
    data
    text
    <p>I'm trying to use the new ASP.Net MVC 4 Web API project template with Ninject but have hit a wall on the following error: </p> <blockquote> <p>Method 'GetFilters' in type 'Ninject.Web.WebApi.Filter.DefaultFilterProvider' from assembly 'Ninject.Web.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' does not have an implementation. </p> </blockquote> <p>I am creating a brand new project in Visual Studio 2010 using the ASP.Net MVC 4 -> Web API template and I am using the latest Ninject NuGet packages:</p> <ul> <li>Ninject 3.0.1.10 </li> <li>Ninject.Web.Common 3.0.0.7</li> <li>Ninject.Web.WebApi 3.0.0.2</li> </ul> <p>I have attempted the solution presented in <a href="https://stackoverflow.com/questions/10849132/mvc4-rc-webapi-binding-with-ninject">this question</a> however I've not had any luck - if I remove the reference to Ninject.Web.WebApi then MVC never engages Ninject. I also notice they mention <strong>Ninject.MVC3</strong> however I am using the new <strong>Ninject.WebApi</strong> plugin.</p> <p>I am using the default binding code in <strong>NinjectWebCommon.cs</strong> that is created during the NuGet install and attempting to register one simple service in <strong>RegisterServices()</strong></p> <pre><code>[assembly: WebActivator.PreApplicationStartMethod(typeof(mkts.web.App_Start.NinjectWebCommon), "Start")] [assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(mkts.web.App_Start.NinjectWebCommon), "Stop")] namespace mkts.web.App_Start { using System; using System.Web; using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Ninject; using Ninject.Web.Common; using mkts.service; public static class NinjectWebCommon { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); /// &lt;summary&gt; /// Starts the application /// &lt;/summary&gt; public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } /// &lt;summary&gt; /// Stops the application. /// &lt;/summary&gt; public static void Stop() { bootstrapper.ShutDown(); } /// &lt;summary&gt; /// Creates the kernel that will manage your application. /// &lt;/summary&gt; /// &lt;returns&gt;The created kernel.&lt;/returns&gt; private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind&lt;Func&lt;IKernel&gt;&gt;().ToMethod(ctx =&gt; () =&gt; new Bootstrapper().Kernel); kernel.Bind&lt;IHttpModule&gt;().To&lt;HttpApplicationInitializationHttpModule&gt;(); RegisterServices(kernel); return kernel; } /// &lt;summary&gt; /// Load your modules or register your services here! /// &lt;/summary&gt; /// &lt;param name="kernel"&gt;The kernel.&lt;/param&gt; private static void RegisterServices(IKernel kernel) { //Test binding kernel.Bind&lt;IStudentService&gt;().To&lt;StudentService&gt;(); } } } </code></pre> <p>My controller:</p> <pre><code>namespace mkts.web.Controllers { public class HomeController : Controller { private readonly IStudentService studentService; public HomeController(IStudentService studentService) { this.studentService = studentService; } public ActionResult Index() { return View(); } } } </code></pre> <p>Many thanks in advance for any help with this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload