次のような動作を説明できる人はいませんか?Structuremap、デフォルトのインスタンスと名前付きインスタンスを使用する場合の奇妙な動作オプション
特にTestUseAndAddが失敗したときにTestInitializeAndConfigure_Failsが失敗し、TestUseOrderChangedが失敗した場合にTestUse_Failsが失敗する理由を教えてください。使用<を呼び出すため
おかげ
コード
interface IResource {}
class TheFirstResource : IResource {}
class TheSecondResource : IResource {}
[TestFixture]
class Test
{
[Test]
public void TestUse_Fails()
{
ObjectFactory.Initialize(init =>
{
init.For<IResource>().Singleton().Use<TheFirstResource>();
init.For<IResource>().Singleton().Use<TheSecondResource>().Named("test");
});
IResource r1 = ObjectFactory.GetInstance<IResource>();
IResource r2 = ObjectFactory.GetNamedInstance<IResource>("test");
Console.WriteLine(string.Format("TestUse_Fails \n{0}\n{1}", r1, r2));
}
[Test]
public void TestUseOrderChanged()
{
ObjectFactory.Initialize(init =>
{
init.For<IResource>().Singleton().Use<TheSecondResource>().Named("test");
init.For<IResource>().Singleton().Use<TheFirstResource>();
});
IResource r1 = ObjectFactory.GetInstance<IResource>();
IResource r2 = ObjectFactory.GetNamedInstance<IResource>("test");
Console.WriteLine(string.Format("TestUseOrderChanged \n{0}\n{1}", r1, r2));
}
[Test]
public void TestUseAndAdd()
{
ObjectFactory.Initialize(init =>
{
init.For<IResource>().Singleton().Use<TheFirstResource>();
init.For<IResource>().Singleton().Add<TheSecondResource>().Named("test");
});
IResource r1 = ObjectFactory.GetInstance<IResource>();
IResource r2 = ObjectFactory.GetNamedInstance<IResource>("test");
Console.WriteLine(string.Format("TestUseAndAdd \n{0}\n{1}", r1, r2));
}
[Test]
public void TestInitializeAndConfigure_Fails()
{
ObjectFactory.Initialize(init =>
{
init.For<IResource>().Singleton().Use<TheFirstResource>();
});
ObjectFactory.Configure(init =>
{
init.For<IResource>().Singleton().Add<TheSecondResource>().Named("test");
});
IResource r1 = ObjectFactory.GetInstance<IResource>();
IResource r2 = ObjectFactory.GetNamedInstance<IResource>("test");
Console.WriteLine(string.Format("TestInitializeAndConfigure_Fails \n{0}\n{1}", r1, r2));
}
}
出力
TestUse_Fails
Smtesting.TheSecondResource
Smtesting.TheSecondResource
TestUseOrderChanged
Smtesting.TheFirstResource
Smtesting.TheSecondResource
TestInitializeAndConfigure_Fails
Smtesting.TheSecondResource
Smtesting.TheSecondResource
TestUseAndAdd
Smtesting.TheFirstResource
Smtesting.TheSecondResource
http://groups.google.com/group/structuremap-users/browse_thread/thread/f567ae92b1b98eae?hl=en – Stig