Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • This is different from SP since there is nothing "global" about this. But how do I access the container? Isn't the container necessarily global? Commented Oct 13, 2020 at 8:04
  • Not necessarily. You would typically have a container for each application "context", where the context creates and initializes the container. But you could have multiple instances of the application in the same process. And it should be fairly easy to change from single to multiple instances. You can also have multiple levels. For example, you could have one "global" container, 0..n containers for text documents, 0..n containers for spreadsheets etc. Commented Oct 13, 2020 at 9:48
  • Thanks for the reply, I think I got it now. Basically, nothing actually needs a reference to the container as long as the container (or main, which can just initialize the container and then has a reference) is the one that instantiates everything as needed. Right? Commented Oct 13, 2020 at 14:56
  • @scenia yes, thats it. There may be exceptions for things like factories, if something need to create multiple instances of some type from the container. UnityContainer allows the container itself to be injected as a dependency, but that should be avoided if possible. Commented Oct 13, 2020 at 15:02