I have an interface of global variables like so:
public interface ClientSettings{
DateTime CurrentClientTime;
string ClientImageFolder;
}
The concrete class is persisted using settings files or a database table.
These values must be accessed by entities and services, both in the domain and the application layer. I have been using DI in my application layer, so access this from there is no problem.
But now that I need to access this interface from the entities I’m not sure of the best way to do so. I don’t really want to inject this into my entities. Is the service locator pattern appropriate here? Or do I have another option all together?
In this type of situation I would try to design the entities and the application layer such that the application layer provides all required settings information to the entities when operating upon them. Settings are normally an application concern and should therefore be managed by the application layer. Furthermore, an application level settings container object, such as
ClientSettingsmay contain settings for various parts of the application which may not be applicable for a given entity. This is another argument for relieving the domain entities of the responsibility.