两个现有对象SetAllProperties()我应该使用它吗?
var theGateway1 = new DefaultGateway();
var something = new Something();
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IGateway>().TheDefault.IsThis(theGateway);
x.ForRequestedType<ISomething>().TheDefault.IsThis(something);
// First we create a new Setter Injection Policy that
// forces StructureMap to inject all public properties
// where the PropertyType is IGateway
x.SetAllProperties(y =>
{
y.OfType<IGateway>();
y.OfType<ISomthing>();
});
});
答案 0 :(得分:0)
如果你真的想用这两个实例注入所有的setter,那没关系。只需使用新语法:
ObjectFactory.Initialize(x =>
{
x.For<IGateway>().Use(theGateway);
x.For<ISomething>().Use(something);
x.SetAllProperties(y =>
{
y.OfType<IGateway>();
y.OfType<ISomething>();
});
});