Chaining containers with StructureMap

2019-07-07 06:04发布

Is it possible to link containers together in StructureMap like it is in WindsorContainer.AddChildContainer()?

I want to achieve having 3 container levels; - 1 page request level - 1 session level - 1 application level

These would then be chained together so only one instance request would be made to the "base level" container.

The levels of container are unimportant really, just whether there is the ability to link them together.

1条回答
戒情不戒烟
2楼-- · 2019-07-07 06:11

This seems to do the trick, not sure if there is a better way or what the implications are. So far looks ok...

childContainer.PluginGraph.Registries.ForEach(
  registry => parentContainer.Configure(expression => expression.AddRegistry(registry))
);

where parentContainer & childContainer are both StructureMap.Container

查看更多
登录 后发表回答