两个存在的对象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>();
});
});
如果你真的想用这两个实例注入所有的setter,这是可以的。只需使用新的语法:
ObjectFactory.Initialize(x =>
{
x.For<IGateway>().Use(theGateway);
x.For<ISomething>().Use(something);
x.SetAllProperties(y =>
{
y.OfType<IGateway>();
y.OfType<ISomething>();
});
});