ServiceObjectLocator
using Relativity.Transfer.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace Relativity.Transfer
{
public static class ServiceObjectLocator
{
private static readonly IDictionary<Type, object> Services = CreateDefaultServices();
public static void Clear()
{
Services.Clear();
}
public static T GetService<T>() where T : class
{
try {
return Services[typeof(T)] as T;
} catch (Exception innerException) {
string message = string.Format(CultureInfo.CurrentCulture, CoreStrings.ServiceNotRegisteredExceptionMessage, typeof(T));
throw new TransferException(message, innerException, true);
}
}
public static void Register<T>(T service)
{
Services[typeof(T)] = service;
}
public static void Reload()
{
Clear();
IDictionary<Type, object> dictionary = CreateDefaultServices();
foreach (Type key in dictionary.Keys) {
Services[key] = dictionary[key];
}
}
private static IDictionary<Type, object> CreateDefaultServices()
{
Dictionary<Type, object> dictionary = new Dictionary<Type, object>();
dictionary.Add(typeof(IFileSystemService), new FileSystemService());
return dictionary;
}
}
}