2
我有一個很奇怪的問題。在我的MVC應用4我有這樣的代碼來初始化StructureMap:StructureMap初始化web表單
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
x.For<IRestHttpClient>().Use<AtlamHttpClient>().Ctor<string>().Is(Settings.AtlamServicesURL);
});
ObjectFactory.AssertConfigurationIsValid();
return ObjectFactory.Container;
}
}
如預期那樣工作。不過,我也有相同的基本初始化代碼.NET 4.5 Web窗體應用程序:
public static class IoC
{
public static IContainer Configure()
{
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.AssemblyContainingType<IRestHttpClient>();
scan.AssemblyContainingType<MessagePackMediaTypeFormatter>();
});
x.For<IRestHttpClient>().Use<AtlamHttpClient>().Ctor<string>().Is(Settings.BaseServiceUrl);
/*x.SetAllProperties(y =>
{
y.OfType<IRestHttpClient>();
});*/
});
ObjectFactory.AssertConfigurationIsValid();
return ObjectFactory.Container;
}
}
拋出的AssertConfigurationIsValid()異常和失敗在這裏AtlamHttpClient:
public static List<ContentNegotiator> extensionMappings = new List<ContentNegotiator>()
{
new ContentNegotiator("xml", "application/xml", new XmlMediaTypeFormatter()),
new ContentNegotiator("json", "application/json", new JsonMediaTypeFormatter()),
new ContentNegotiator("pack", "application/x-msgpack", new MessagePackMediaTypeFormatter())
};
這依次調用:
public MessagePackMediaTypeFormatter()
{
MediaTypeHeaderValue val = MediaTypeHeaderValue.Parse(mime);
SupportedMediaTypes.Add(val);
}
並因ArrayTypeMismatchException失敗。無法弄清楚爲什麼第一個項目工作正常,第二個失敗。任何幫助將不勝感激。
我應該補充說兩個項目都使用了StructureMap 2.6.4版本。 –