I am now working on plugin architecture which will enable user to drop dll into plugins folder and then by invoking Start on the plugin object, it will do the necessary component registration, routing etc.
The problem here is eventhough I use AppDomain.Current.Load() and do the routing, I can't make it work. This is the error that I get
The controller for path '/Gallery/Index' could not be found or it does not implement the IController interface.
But if I drop the dll into bin folder, everything works as expected.
#endregion
}
public class BlogMvcHandler:System.Web.Mvc.MvcHandler
{
protected override void ProcessRequest(IHttpContext httpContext)
{
if (this.RequestContext == null)
throw new InvalidOperationException("No RequestContext");
Type controllerType = this.RequestContext.RouteData.Values["controllertype"] as Type;
tehlike
Member
70 Points
25 Posts
Controller in Dynamically Loaded Assembly
Mar 03, 2008 07:41 PM|LINK
Hello everybody,
I am working on a blog application which is available at http://blogcontroller.googlecode.com/.
I am now working on plugin architecture which will enable user to drop dll into plugins folder and then by invoking Start on the plugin object, it will do the necessary component registration, routing etc.
The problem here is eventhough I use AppDomain.Current.Load() and do the routing, I can't make it work. This is the error that I get
The controller for path '/Gallery/Index' could not be found or it does not implement the IController interface.
But if I drop the dll into bin folder, everything works as expected.
Thanks!
tehlike
Member
70 Points
25 Posts
Re: Controller in Dynamically Loaded Assembly
Mar 03, 2008 07:47 PM|LINK
PS:
When I look at assemblies loaded into AppDomain, I can see my plugin assembly.
tehlike
Member
70 Points
25 Posts
Re: Controller in Dynamically Loaded Assembly
Mar 04, 2008 06:11 AM|LINK
Yeap, there we go
public class BlogRouteHandler : System.Web.Mvc.IRouteHandler
{
#region IRouteHandler Members
public System.Web.IHttpHandler GetHttpHandler(System.Web.Mvc.RequestContext requestContext)
{
BlogMvcHandler blogHandler=new BlogMvcHandler();
blogHandler.RequestContext = requestContext;
return blogHandler;
}
#endregion
}
public class BlogMvcHandler:System.Web.Mvc.MvcHandler
{
protected override void ProcessRequest(IHttpContext httpContext)
{
if (this.RequestContext == null)
throw new InvalidOperationException("No RequestContext");
Type controllerType = this.RequestContext.RouteData.Values["controllertype"] as Type;
IController controller = ControllerBuilder.Current.CreateController(this.RequestContext, controllerType);
ControllerContext controllerContext = new ControllerContext(base.RequestContext, controller);
controller.Execute(controllerContext);
}
}
and I set the route like
RouteTable.Routes.Add(new Route
{
Url = "Gallery/Index",
Defaults = new { controller="gallery",controllertype = typeof(GalleryController), action = "Index" },
RouteHandler = typeof(BlogRouteHandler)
});
A better way would be directly obtaining the controller type from the container but this works anyway.
Not intended to use in production.