私は非常に奇妙な問題を抱えています。私の MVC 4 アプリケーションには、 StructureMap を初期化するための次のコードがあります。
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 で失敗します。最初のプロジェクトが正常に動作し、2 番目のプロジェクトが失敗する理由がわかりません。どんな助けでも大歓迎です。