I am using StructureMap to resolve dependency, which works fine with older version.But after updating StructureMap version 4.2.0.40, i am facing this error.
ObjectFactory is now obsoleted in new version. So how to modify below logic to fit this with updated version.
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
try
{
if ((requestContext == null) || (controllerType == null))
return null;
return (Controller)ObjectFactory.GetInstance(controllerType);
}
catch (StructureMapException)
{
System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
throw new Exception(ObjectFactory.WhatDoIHave());
}
}
Bootstrapper.cs
public static class Bootstrapper
{
public static void Run()
{
ControllerBuilder.Current
.SetControllerFactory(new StructureMapControllerFactory());
ObjectFactory.Initialize(x =>
{
x.AddConfigurationFromXmlFile(@"D:\Samples\Web_API\OneCode\StructureMap.Web\StructureMap.Web\StructureMap.xml");
});
}
}
}