I’m wondering how I should store/reference my dependency injection container(s). Is it alright to have a container be a static property on a static class? Or should I have the container be an instance variable on the application? I’m wondering what the pros and cons of each option are, and what is the best practice for this in web, mvc, console, and windows apps?
I’m wondering how I should store/reference my dependency injection container(s). Is it alright to
Share
I recommend storing it as an instance variable on the application. Using a static property – making it a globally accessible singleton – hides your application’s dependency on it, which is one of the things you’re trying to get away from by using a dependency injection container in the first place!
Having said that, if your framework makes it difficult for you to access your application instance, it wouldn’t be the end of the world to use a static variable.