我有一个使用依赖注入的控制器:
public FeedController(IFeedProcessor feedProcessor)
{
_feedProcessor = feedProcessor;
}
这是我的配置代码:
public static void Config()
{
ObjectFactory.Initialize(x => x.Scan(scan =>
{
x.For<IFeedProcessor>().Use<FeedProcessor>();
}));
}
我的 FeedProcessor 类有参数构造函数:
public FeedProcessor(IFeedParserFactory ifeedParserFactory)
{
_ifeedParserFactory = ifeedParserFactory;
}
这个 StructureMapControllerFactory :
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
if (requestContext.HttpContext.Request.Url != null)
throw new InvalidOperationException(string.Format("Page not found: {0}", requestContext.HttpContext.Request.Url.AbsoluteUri.ToString(CultureInfo.InvariantCulture)));
return ObjectFactory.GetInstance(controllerType) as Controller;
}
}
我得到这个错误:类型'Api.Controllers.FeedController'没有默认构造函数我如何为这种情况配置结构图?