Locator of ELMA Services
All ELMA components are integrated using two key layers:
- Extension points
- Services
Extension points are interfaces, used to extend ELMA basic functions with additional modules. Services can be interfaces too and they determine ELMA global functions. For example, security service is used for checking access permissions for ELMA objects.
Using services
ELMA uses Inversion of Control (IoC) principle when all implementations of services are registered as interfaces (abstractions) in the Locator class.
ELMA provides a static class for accessing components and services: EleWise.ELMA.Services.Locator.
Below is the full description of Locator class methods:
namespace EleWise.ELMA.Services
{
/// <summary>
/// Manager of services
/// </summary>
public static class Locator
{
/// <summary>
/// Label, that the manager is initialized
/// </summary>
public static bool Initialized
{
get;
}
/// <summary>
/// Register Service
/// </summary>
/// <param name="type">Service type</param>
/// <param name="obj">Service</param>
public static void AddService(Type type, object obj);
/// <summary>
/// Register Service
/// </summary>
/// <param name="type">Service type</param>
/// <param name="obj">Service</param>
/// <param name="resolveProperties">Process public properties when registering</param>
public static void AddService(Type type, object obj, bool resolveProperties);
/// <summary>
/// Register Existing Service
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <param name="obj">Service</param>
public static void AddService<T>(T obj);
/// <summary>
/// Register Existing Service
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <param name="obj">Service</param>
/// <param name="resolveProperties">Process public properties when registering</param>
public static void AddService<T>(T obj, bool resolveProperties);
/// <summary>
/// Get the service with the specified type and name, with or without checking services existance
/// </summary>
/// <param name="type">Service type</param>
/// <param name="name">Service name</param>
/// <param name="checkNotNull">Whether to check, if the service exists</param>
/// <returns>Requested service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
/// <exception cref="EleWise.ELMA.Exceptions.ServiceNotFoundException">If the requested service is not found</exception>
[CanBeNull]
public static object GetService(Type type, string name, bool checkNotNull);
/// <summary>
/// Get the service with the specified type and name (without existance check)
/// </summary>
/// <param name="type">Service type</param>
/// <param name="name">Service name</param>
/// <returns>Requested Service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
[CanBeNull]
public static object GetService(Type type, string name);
/// <summary>
/// Get the service with the specified type and name (with existance check)
/// </summary>
/// <param name="type">Service type</param>
/// <param name="name">Service name</param>
/// <returns>Requested Service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
/// <exception cref="EleWise.ELMA.Exceptions.ServiceNotFoundException">If the requested service is not found</exception>
[NotNull]
public static object GetServiceNotNull(Type type, string name);
/// <summary>
/// Get Service of the specified type (without existance check)
/// </summary>
/// <param name="type">Service type</param>
/// <returns>Requested service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
[CanBeNull]
public static object GetService(Type type);
/// <summary>
/// Get Service of the specified type (with existance check)
/// </summary>
/// <param name="type">Service type</param>
/// <returns>Requested Service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
/// <exception cref="EleWise.ELMA.Exceptions.ServiceNotFoundException">If the requested service is not found</exception>
[NotNull]
public static object GetServiceNotNull(Type type);
/// <summary>
/// Get the service with the specified type and name (without existance check)
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <returns>Requested Service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
[CanBeNull]
public static T GetService<T>();
/// <summary>
/// Get Service of the specified type (with existance check)
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <returns>Requested Service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
/// <exception cref="EleWise.ELMA.Exceptions.ServiceNotFoundException">If the requested service is not found</exception>
[NotNull]
public static T GetServiceNotNull<T>();
/// <summary>
/// Get the service with the specified type and name (without existance check)
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <param name="name">Service name</param>
/// <returns>Requested service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
[CanBeNull]
public static T GetService<T>(string name);
/// <summary>
/// Get the service with the specified type and name (with existance check)
/// </summary>
/// <typeparam name="T">Service type</typeparam>
/// <param name="name">Service name</param>
/// <returns>Requested service</returns>
/// <exception cref="EleWise.ELMA.Exceptions.NotInitializedException">If the services manager is not initialized</exception>
/// <exception cref="EleWise.ELMA.Exceptions.ServiceNotFoundException">If the requested service is not found</exception>
[NotNull]
public static T GetServiceNotNull<T>(string name);
/// <summary>
/// Set Services Manager Implementation
/// </summary>
/// <param name="locatorImpl">Services Manager Implementation</param>
public static void SetImpl (ILocatorImpl locatorImpl);
/// <summary>
/// Unregister Service
/// </summary>
/// <param name="type">Service type</param>
public static void RemoveService(Type type);
}
}
Usually, you need to use Locator in scripts to call necessary services. To do so, invoke GetService() or GetServiceNotNull() methods:
// Receive the authentication service
var authService = Locator.GetServiceNotNull<IAuthenticationService>();
// Receive the security service
var securityService = Locator.GetServiceNotNull<ISecurityService>();
//Check if the current user has access to the objects
if (!securityService.HasPermission(authService.GetCurrentUser(), EleWise.ELMA.Common.PermissionProvider.CatalogsAccessPermission))
{
throw new SecurityException("No access to objects");
}
Note that all object managers are services as well.
You can find the list of available system services in ELMA API help.