thank you for your answer. I had already followed the indications during the setup of my solution.
At this point I'm a bit confused...
So, global.asax is
public class Global : UmbracoApplication
{
public static IWindsorContainer Container;
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
Bootstrap.BootstrapApplication();
}
protected override void OnApplicationStarted(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
var bundles = Container.Kernel.ResolveAll<IBundleInstaller>();
foreach (var b in bundles)
{
b.Install(BundleTable.Bundles);
}
Routes.RegisterRoutes(RouteTable.Routes);
}
protected override void OnApplicationEnd(object sender, EventArgs e)
{
base.OnApplicationEnd(sender, e);
Container.Dispose();
}
}
The bootstrap class
public static class Bootstrap
{
public static void BootstrapApplication()
{
Global.Container = new WindsorContainer()
.Install(FromAssembly.This(),
FromAssembly.Named("Umb.Firenze")
);
DependencyResolver.SetResolver(new WindsorDependencyResolver(Global.Container.Kernel));
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorCompositionRoot(Global.Container));
FilteredControllerFactoriesResolver.Current.InsertType<FilteredControllerFactory>(0);
}
}
WindsorDependencyResolver
public class WindsorDependencyResolver : System.Web.Mvc.IDependencyResolver
{
private readonly IKernel kernel;
public WindsorDependencyResolver(IKernel kernel)
{
this.kernel = kernel;
}
public object GetService(Type serviceType)
{
return this.kernel.HasComponent(serviceType) ? this.kernel.Resolve(serviceType) : null;
}
public IEnumerable<object> GetServices(Type serviceType)
{
return this.kernel.ResolveAll(serviceType) as IEnumerable<object>;
}
}
If I run in debug mode, the filtered controller factory seems to never fire.
I dug a bit into this and maybe I have some clues.
I've copied the Umbraco.Web.Mvc.MasterControllerFactory from the source code, changed the namespace and set as my default factory to go in there in debug bug.
It seems that FilteredControllerFactoriesResolver.Factory contains only the default umbraco value (Umbraco.Web.Mvc.RenderControllerFactory), while my custom controller factory in only registered in InstanceTypes, thus never invoked.
I have no idea why or what should i do to fix this...
Umbraco dynamic routing
Hi everyone,
I'm developing a website using Glass.Mapper and Castle.Windsor
My goal is to develop a site which is skinnable, so I want to use different controllers for a given url based on a configuration parameter.
For example: for the document type TestType
I want to dynamically choose the controller TestTypeController which exist in two different namespaces, based on a configuration parameter.
Someone can point me out how to correctly work with the umbraco pipeline?
Thank you very much :)
See the bottom part about creating a filteredcontrollerfactory here: https://our.umbraco.org/documentation/Reference/Templating/Mvc/using-ioc
Hi Lars,
thank you for your answer. I had already followed the indications during the setup of my solution.
At this point I'm a bit confused...
So, global.asax is
The bootstrap class
WindsorDependencyResolver
Some other code
And finally the route table
If I run in debug mode, the filtered controller factory seems to never fire.
I dug a bit into this and maybe I have some clues.
I've copied the Umbraco.Web.Mvc.MasterControllerFactory from the source code, changed the namespace and set as my default factory to go in there in debug bug.
It seems that FilteredControllerFactoriesResolver.Factory contains only the default umbraco value (Umbraco.Web.Mvc.RenderControllerFactory), while my custom controller factory in only registered in InstanceTypes, thus never invoked.
I have no idea why or what should i do to fix this...
Finally i got the solution!
The problem was on my FilteredControllerFactory, that needed a parameterless controller.
I solved the issue changing the .ctor like this
public FilteredControllerFactory() : base(Global.Container.Kernel) { }
is working on a reply...