如何用 StructureMap 装饰一个依赖两次

How to decorate a dependency twice with StructureMap

我在StructureMap中配置了一个依赖,想装饰它两次。我使用了如下所示的 EnrichWith 方法,但只执行了第二个装饰器 (ResultistAdvertisementInjector)。如果我切换它们,只会执行另一个装饰器。

For<IResultListViewModelMapper<ZoekObject>>().Use<ResultListViewModelMapper<ZoekObject>>()
    .EnrichWith(original => new ResultListDateSeparatorInjector<ZoekObject>(original))
    .EnrichWith(original => new ResultistAdvertisementInjector<ZoekObject>(original));

如何使用两个装饰器丰富依赖项?

在我的脑海中,我认为你可以做这样的事情:

For<IResultListViewModelMapper<ZoekObject>>()
    .Use<ResultListViewModelMapper<ZoekObject>>()
    .EnrichWith(original =>
        new ResultListDateSeparatorInjector<ZoekObject>(
            new ResultistAdvertisementInjector<ZoekObject>(original)));

您可以自己嵌套 'decorating' 类,例如:

For<IResultListViewModelMapper<ZoekObject>>().Use<ResultListViewModelMapper<ZoekObject>>()
                .EnrichWith(original => 
                new ResultListDateSeparatorInjector<ZoekObject>(
                    new ResultistAdvertisementInjector<ZoekObject>(original)));