我希望使用 StructureMap 为每个 ObjectFactory.Getinstance() 调用创建一个对象的新实例。我自己无法找到或弄清楚。
AlwaysUnique 没有这样做。
[TestMethod]
public void GetConcreteInstanceOf_ShouldReturn_DifferentInstance()
{
ObjectFactory.Initialize(registry =>
{
// setup the singleton, so that it's new every time
registry.For<ISystemData>().AlwaysUnique().Use(new SystemDataClient());
});
ISystemData result = ObjectFactory.GetInstance<ISystemData>();
ISystemData result2 = ObjectFactory.GetInstance<ISystemData>();
Assert.AreNotSame(result, result2);
}