I have a User object that has a HasCompletedSecurity property that indicates whether that particular User answered the number of security questions required by the system. The number of security issues required by the system is configured and retrieved from the configuration file. How does the User class access configured information?
I currently have an IConfigurationService interface behind which I have implementations that use the equivalent of ConfigurationManager or Azure, if available. I encapsulated access to my DI container through the static InjectionService class, and currently I am allowing the configured value as follows:
public class User { private static readonly IConfigurationService _configurationService = InjectionService.Resolve<IConfigurationService>(); public bool HasCompletedSecurity { get {
This, of course, is an example of the ServiceLocator antivirus template , and I don't like it. Static dependency makes unit testing anything that uses this class inconveniently.
I use the Entity Framework and take a replica from here I donβt want to pass my entities through the DI container to give their dependencies, so ... how do I access the configured value?
Change With this one-sided example (and I appreciate the suggestions for the right architecture for it), the more important question that interests me is the static links to services from entities? Is the answer simply an architect of entities in a way that you never need?
Steve wilkes
source share