我在StructureMap中配置了一个依赖项,并且想要将它装饰两次。我使用了下面的EnrichWith
方法,但只执行了第二个装饰器(ResultistAdvertisementInjector
)。如果我切换它们只会执行另一个装饰器。
For<IResultListViewModelMapper<ZoekObject>>().Use<ResultListViewModelMapper<ZoekObject>>()
.EnrichWith(original => new ResultListDateSeparatorInjector<ZoekObject>(original))
.EnrichWith(original => new ResultistAdvertisementInjector<ZoekObject>(original));
如何使用两个装饰器来丰富依赖项?
答案 0 :(得分:2)
你可以在“装饰”中筑巢。自己上课,例如:
For<IResultListViewModelMapper<ZoekObject>>().Use<ResultListViewModelMapper<ZoekObject>>()
.EnrichWith(original =>
new ResultListDateSeparatorInjector<ZoekObject>(
new ResultistAdvertisementInjector<ZoekObject>(original)));
答案 1 :(得分:0)
在我的头脑中,我认为你可以这样做:
For<IResultListViewModelMapper<ZoekObject>>()
.Use<ResultListViewModelMapper<ZoekObject>>()
.EnrichWith(original =>
new ResultListDateSeparatorInjector<ZoekObject>(
new ResultistAdvertisementInjector<ZoekObject>(original)));