示例#1
0
 public static void Register <T>(string serviceName, T obj)
 {
     if (RegisteredServices.ContainsKey(serviceName))
     {
         throw new Exception($"Service {serviceName} has already been registered.");
     }
     RegisteredServices.Add(serviceName, obj);
 }
示例#2
0
 public static T Resolve <T>(string serviceName, bool dontThrow = false)
 {
     if (RegisteredServices.ContainsKey(serviceName))
     {
         return((T)RegisteredServices[serviceName]);
     }
     if (dontThrow)
     {
         return((T)(object)null);
     }
     throw new Exception($"Service {serviceName} is not registered.");
 }