Custom View Engine in Asp.net MVC

42 views
Skip to first unread message

Michael

unread,
Mar 10, 2010, 3:53:22 PM3/10/10
to ninject
We are using ninject in a ASP>net MVC app and it's working great. I
now have to extend my viewengine to allow for different views based on
subdomain. When I register my new viewengine n the global.asax , it's
like ninject highjacks the request and it doens;t go through. The path
to the view does not get rewritten according to my viewengine. I am
able to use my custom view engine in another app (not using ninject).
I would greatly appreciate any help with this problem. Thanks in
advance for any help.

If any more details are needed I can provide them, Thanks

claco

unread,
Mar 10, 2010, 4:35:24 PM3/10/10
to ninject
Define "When I register my new viewengine n the global.asax" with an
example.

Are you calling ViewEngines.Engines.Clear first?
You can "stack" view engines, so it's possible the default engine is
picking up the request first.

I actually have 3 engines stacked using ninject to get all all
bindings for IViewEngine without any issues.

Michael

unread,
Mar 10, 2010, 4:52:41 PM3/10/10
to ninject
I am calling clear first. Here is my global.

public class MvcApplication : NinjectHttpApplication
{
protected override void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(

"Default", // Route name
"{controller}/{action}/
{id}", // URL with parameters
new { controller = "Client", action = "Index", id =
"" } // Parameter defaults
);
}

protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
InitializeNinject();
System.Web.Mvc.ViewEngines.Engines.Clear();
System.Web.Mvc.ViewEngines.Engines.Add(new
WebFormThemeViewEngine());
}


public void InitializeNinject()
{
//NinjectKernel.Initialize(new
ControllerModule(Assembly.GetExecutingAssembly()));

ControllerBuilder.Current.SetControllerFactory(typeof(NinjectControllerFactory));
}

protected override IKernel CreateKernel()
{
IModule[] modules = new IModule[]
{
new
AutoControllerModule(Assembly.GetExecutingAssembly()),
new SnapModule()
};
return new StandardKernel(modules);

Reply all
Reply to author
Forward
0 new messages