Service Locator Assembly
The service locator assembly includes a service locator class. This class instantiates services that are used in the application. The following figure illustrates this.
This assembly implements the Service Locator pattern for the components that are provided by the Training Management application. For more information about the Service Locator pattern, see The Service Locator Pattern in this guidance and Service Locator on MSDN.
The Training Management application's ServiceLocator class locates services and also functions as an object factory. In the released version of the Training Management application, the Get<T> method constructs and returns a new object instance each time it is called. This behavior is intentional. In earlier implementations, the ServiceLocator class maintained a set of object instances that were shared across the application. However, this increased the risk of threading issues because the object instances that were accessed through the ServiceLocator class could be simultaneously used by multiple users. If correct thread locking or transaction management is not in place, the object can be in an inconsistent state when it is accessed. Constructing and returning new object instances for each call to the Get<T> method discourages storing shared state in instance-scoped member variables. If you must use shared state, carefully plan where the shared state is stored and how it is accessed.