Skip to content

Instantly share code, notes, and snippets.

@leethomascook
Created February 6, 2014 10:22
Show Gist options
  • Save leethomascook/8841684 to your computer and use it in GitHub Desktop.
Save leethomascook/8841684 to your computer and use it in GitHub Desktop.
StructureMap and umbraco 7
In Global.asax
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
ObjectFactory.Configure(
x => x.For<ITest>().Use<Test>()
);
FilteredControllerFactoriesResolver.Current.RemoveType<RenderControllerFactory>();
FilteredControllerFactoriesResolver.Current.AddType<CustomControllerFactory>();
}
------------
public class CustomControllerFactory : RenderControllerFactory
{
public override Type GetControllerType(RequestContext requestContext, string controllerName)
{
return base.GetControllerType(requestContext, controllerName);
}
public override IController CreateController(RequestContext requestContext, string controllerName)
{
var type = base.GetControllerType(requestContext, controllerName);
return ObjectFactory.GetInstance(type) as Controller;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment