Reputation: 9459
I've set up StructureMap as my choice for DI and upon registering my custom controller factory, this error pops up (the error doesn't pop if StructureMap isn't set up). I don't know why this error occurs, it seems oddly buggy, am I missing anything? I've seen comments to this issue around SO but no definitive answer. If there is a correct fix for this that I missed, would you kindly point me in the right direction?
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
var appRepo = new ApplicationDbContext();
var settingsRepo = new SettingRepository(appRepo);
if (controllerType == typeof(SettingsController))
{
return new SettingsController(settingsRepo);
}
return base.GetControllerInstance(requestContext, controllerType);
}
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// This initializes our database
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
Upvotes: 1
Views: 3613
Reputation: 3164
I've just had this perhaps misleading message, when running in debug mode. What has happened for me is that I have removed modernizr from my BundleConfig.cs
//bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
// "~/Scripts/modernizr-*"));
but when I have created new Areas in my project, it has scaffolded in the call to load modernizr
@Scripts.Render("~/bundles/modernizr")
You need to remove this call to the non-existant bundle. I would suggest it is the same issue that you were having.
I'm sure this information will help somebody in the future.
Upvotes: 1