The surrounding context is fine when you need to implement functionality spanning multiple layers. (In your case, you say that these two objects are global). This functionality is known as cross-reference issues . As you noticed, many classes in .NET are implemented as an ambient context , such as IPrincipal . To get a working version of your implementation of the surrounding context, you will need to have a default value for the Settings and Language objects, if they are designed as the surrounding context. My guess is that you will provide the default implementation of ILanguage and ISettings by default, and given that you will use them globally, they are good candidates for the surrounding context.
On the other hand, how often do you plan to use those objects that implement these two interfaces? And is there an existence of two objects having the value Settings != null and Language != null ? If you are really going to use them in one or two classes and / or if the existence of objects is not very important, you can go with the installation . Setter injection does not really require a default, so your object may be null .
Personally, I am not a fan of the surrounding context. However, I would use it if it turned out to be the most acceptable solution. In the case of your implementations, I would do something like this: because you will need to initialize objects that implement two interfaces once and only in one place, you can start with the surrounding context. If you realize that you are using it in a very small number of places, consider reorganizing it as a setter injection. If the existence of objects is important, consider implementing a constructor implementation .
Husein roncevic
source share