Is it correct to have many Castle Windsor containers per application if those containers belong to different tiers?

后端 未结 3 1744
南方客
南方客 2021-01-28 23:53

I\'ve been playing around with Castle Windsor lately and realized I could use it to back a container-like object I currently use already. So far I\'ve only read information abou

相关标签:
3条回答
  • 2021-01-28 23:59

    I don't think it is such a good idea to have many independent containers. You may however want to have an application-wide mother container and child containers with more narrow scope.

    0 讨论(0)
  • 2021-01-28 23:59

    You may use child kernels, probably? But I don't like the idea very much.

    0 讨论(0)
  • 2021-01-29 00:06

    Personally, I don't have any problem using just one container. After all, your MonoRail controllers will only be aware of the services/interfaces they need so they don't need to know about the inner components of other tiers.

    If you still don't want to make your inner components so visible to the rest of the app, here are a couple of ideas:

    • Wrap your related components in facilities. This will help simplify you inner components' configuration and keep it private.
    • Delegate component instantiation to your container-like object, using factories or subdependencies resolvers (ref1, ref2, ref3)
    • Use child containers. I've never tried them but it looks like it could help in this situation (see ref1, ref2, ref3).

    Whatever you do, you don't want to have every component accessing the container directly. If anything, keep it in your "glue code".

    0 讨论(0)
提交回复
热议问题