应该只有一个地方发生这种情况,您的容器不应该需要在组合根之外使用。
引用从以下链接的答案之一:
In practice,this means that you
should configure the container at the
root of your application.
- In a desktop app,that would be in the Main method (or very close to it)
- In an ASP.NET (including MVC) application,that would be in
Global.asax- In WCF,that would be in a ServiceHostFactory
- etc.
有一个很好的答复here这解释了一点更多。
参见this answer。