Note that there are some explanatory texts on larger screens.

plurals
  1. POParameterized controller constructor never gets hit
    text
    copied!<p>With my pet project I'm trying to learn to use Turbine as a DI container.</p> <p>I'm registering unity as locatorprovider as such:</p> <pre><code>static MvcApplication() { ServiceLocatorManager.SetLocatorProvider(() =&gt; new UnityServiceLocator()); } </code></pre> <p>My user repository has a parameterless constructor and I'm registering it as such:</p> <pre><code>public class UserRepositoryRegistration : IServiceRegistration { public void Register(IServiceLocator locator) { locator.Register&lt;IUserRepository, UserRepository&gt;(); } } </code></pre> <p>Then I have my HomeController which should accept an IUserRepository</p> <pre><code>public class HomeController : Controller { private readonly IUserRepository userRepository; public HomeController(IUserRepository repository) { userRepository = repository; } } </code></pre> <p>If I leave out the parameterless ctor (like in the above code snippet) I get this (<a href="http://pastebin.ca/1706871" rel="nofollow noreferrer">full here</a>):</p> <pre> Server Error in '/' Application. No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. [InvalidOperationException: An error occurred when trying to create a controller of type 'Boris.BeekProject.Guis.Web.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.] </pre> <p>So my HomeController is obligated to have a parless ctor. It seems it's not the Unity controller factory that's instantiating, but rather the default one. </p> <p><strong>UPDATE</strong><br> My MVCApplication is inheriting TurbineApplication and since the RouteRegistration is picked up just fine I think the problem lies somewhere else.</p> <p><strong>UPDATE</strong><br> As suggested by Thomas Eyde I wanted to override the <code>TurbineApplication.AutoComponent</code> method, but checking the Object Browser, I can't see any reference to this method. Furthermore when I look at the NerdDinner example, it doesn't seem to override this method either. After checking the <a href="http://mvcturbine.codeplex.com/wikipage?title=AutoRegistration&amp;referringTitle=Documentation" rel="nofollow noreferrer">online documentation about it</a> I failed to get any the wiser and following the link to documentation about <a href="http://mvcturbine.codeplex.com/wikipage?title=ManualRegistration&amp;referringTitle=AutoRegistration" rel="nofollow noreferrer">doing the registration manually</a> serves me a placeholder page. Can anybody fill me on on what I'm doing wrong?</p> <p>Am I missing something?</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