asp.net mvc - MVC - Creating a Castle Windsor Controller Factory - No parameterless constructor defined for this object -


i introducing di ms mvc application , having trouble getting controllers instantiated within custom controller factory. seems overridden "getcontrollerinstance" not being called.

can tell me missing?

my controller factory:

public class windsorcontrollerfactory : defaultcontrollerfactory {     public windsorcontrollerfactory()     {         var controllertypes = t in appdomain.currentdomain.getassemblies().selectmany(a => a.gettypes())                               typeof (icontroller).isassignablefrom(t)                               select t;         foreach (type controllertype in controllertypes)         {             applicationcontainer.container.addcomponentlifestyle(controllertype.fullname, controllertype,                                                                  lifestyletype.transient);         }     }      protected override icontroller getcontrollerinstance(system.web.routing.requestcontext requestcontext, type controllertype)     {         if(controllertype !=null)         {             return (icontroller) applicationcontainer.container.resolve(controllertype);         }         return base.getcontrollerinstance(requestcontext, controllertype);     } } 

}

application_start:

controllerbuilder.current.setcontrollerfactory(new windsorcontrollerfactory());     } 

the controller factory instantiated , seem not used resolve controller. placed breakpoint on 'getcontrollerinstance' never hit.

the result no parameterless constructor defined object. exception thrown

update:

i changed getcontrollerinstance this:

 private windsorcontainer _container;      public windsorcontrollerfactory(windsorcontainer container)     {         _container = container;         _container.register(alltypes.of<icontroller>().fromassembly(       typeof(basefactorycontroller).assembly).configure(           c => c.named(c.implementation.name.tolowerinvariant()).lifestyle.transient));     } 

now have ignore null controllertype ?! if not commented:

//base.getcontrollerinstance(requestcontext, controllertype);

it begins treat .js files controller. throws httpexception

protected override icontroller getcontrollerinstance(system.web.routing.requestcontext requestcontext, type controllertype)     {         if (controllertype == null)         {             return null;         }         //base.getcontrollerinstance(requestcontext, controllertype);         return (icontroller) _container.resolve(controllertype);     }   

see creating windsorcontainer results in type conversion error (not quite same question, it's same answer nevertheless)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -