title: How to register a controller with parameterized constructor, programatically? (in Castle Windsor - ASP.NET MVC)
body: <p>I want to register controllers programatically in <strong>Global.asax.cs</strong>.
  with MvcContrib.Castle.WindsorControllerFactory</p>
  
  <pre><code>private static IWindsorContainer _Container;
  
  protected virtual void InitializeWindsor()
          {
              try
              {
                  if (_Container == null)
                  {
                      _Container = new WindsorContainer();
                      ControllerBuilder.Current.SetControllerFactory(new MvcContrib.Castle.WindsorControllerFactory(_Container));
  
                      RegisterActiveRecord();
                      RegisterRepositories();
                      RegisterServices();  
                      RegisterControllers();
                      RegisterComponents();
                  }
  </code></pre>
  
  <p>I have done it by</p>
  
  <pre><code> private void RegisterControllers()
          {
              try
              {
                  _Container.Register(
                      AllTypes.Of&lt;IController&gt;()
                      .FromAssembly(typeof(HomeController).Assembly)
                      .Configure(c =&gt; c.LifeStyle.Transient)
                      );
  </code></pre>
  
  <p>It works fine for all controllers with default constructors.
  But, I have a controller (LoginController) with parameterzied construtor.</p>
  
  <pre><code>public class LoginController : Controller
      {
          private IUser _User;
  
          public LoginController(IUser objUser)
          {
              _User = objUser;
          }
  </code></pre>
  
  <p>When I tried to view it in browser (http://localhost:2011/Login), it gives me following error.</p>
  
  <pre><code>**No parameterless constructor defined for this object**
  Stack Trace: 
  [MissingMethodException: No parameterless constructor defined for this object.]
     System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
     System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
     System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
     System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
     System.Activator.CreateInstance(Type type) +6
     System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +491
  
  [InvalidOperationException: An error occurred when trying to create a controller of type 'NAATEELib.Controllers.LoginController'. Make sure that the controller has a parameterless public constructor.]
     System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +628
     System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +204
  </code></pre>
  
  <p>Please guide me. I do not want to modify .config (xml) files.
  thanks.</p>