我有一個使用依賴注入的控制器:鍵入'Api.Controllers。'沒有一個默認的構造函數
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;
}
This 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'沒有默認構造函數 如何配置此場景的結構映射?
請將您的代碼發佈到哪裏設置您的依賴關係解析器! – nemesv 2013-04-20 19:17:25
我更新我的問題 – 2013-04-20 19:20:53
您的IFeedParserFactory(FeedController的依賴關係)是否正確註冊? – 2013-04-20 19:27:53