Share via


Service Locator Assembly

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The service locator assembly includes a service locator class. This class instantiates services that are used in the application. Figure 1 illustrates this.

Ff647944.training_manage_locator(en-us,PandP.10).png

Figure 1
Service locator

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 Design Patterns 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.

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Footer image

To provide feedback, get assistance, or download additional, please visit the SharePoint Guidance Community Web site.

Copyright © 2008 by Microsoft Corporation. All rights reserved.