Note that there are some explanatory texts on larger screens.

plurals
  1. PONinject not binding object in BaseController in MVC3
    text
    copied!<p>I just upgraded my MVC2 project to MVC3 and used the NuGet library package reference to install ninject. This created an appstart class and i used the following code to inject my IMembershipService class.</p> <pre><code>public static void RegisterServices(IKernel kernel) { kernel.Bind&lt;IMembershipService&gt;().To&lt;AccountMembershipService&gt;(); } </code></pre> <p>This works great with my HomeController, for example.</p> <pre><code>public class HomeController : Controller { public IMembershipService MembershipService { get; set; } public HomeController() : this(null) { } public HomeController(IMembershipService service) { MembershipService = service; } </code></pre> <p>HOWEVER, I am using a BaseController. Nearly the same code in the base class no longer works.</p> <pre><code>public class BaseController : Controller { public IMembershipService MembershipService { get; set; } public UserService UserService { get; set; } public BaseController() : this(null, null) { } public BaseController(IMembershipService service, UserService userService) { MembershipService = service; UserService = userService ?? new UserService(); } </code></pre> <p>If I break in the constructor of the base controller, service is just NULL. I have never used Ninject for IOC so perhaps the answer is obvious, but why will it not inject my AccountMembershipController in the base class like I want it to? I don't see what is different, although i realize the extra level of inheritance may be messing with Ninject somehow.</p>
 

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