我正在使用 StructureMap 来解决依赖关系,它适用于旧版本。但是在更新 StructureMap 版本 4.2.0.40 后,我遇到了这个错误。
ObjectFactory 现在在新版本中已过时。 那么如何修改下面的逻辑以适应更新版本。
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());
}
}
引导程序.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");
});
}
}
}