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) {
throw new TransferException(string.Format(CultureInfo.CurrentCulture, CoreStrings.ServiceNotRegisteredExceptionMessage, typeof(T)), 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()
{
return new Dictionary<Type, object> {
{
typeof(IFileSystemService),
new FileSystemService()
}
};
}
}
}