示例#1
0
        public static T GetModuleOrThrow <T>(this IInjector injector) where T : class
        {
            var t = (T?)injector.GetModule(typeof(T));

            if (t is null)
            {
                throw new Exception($"{typeof(T).Name} was not found");
            }
            return(t);
        }
示例#2
0
 /// <summary>Creates all modules.</summary>
 /// <returns>True if all are initialized, false otherwise.</returns>
 public bool Build()
 {
     for (var curNode = modules.Last; curNode != null; curNode = curNode.Previous, modules.RemoveLast())
     {
         var cur = curNode.Value;
         var obj = injector.GetModule(cur.TImplementation);
         if (obj != null)
         {
             injector.AddModule(cur.TService, obj);
         }
         else
         {
             if (!injector.TryCreate(cur.TImplementation, out obj))
             {
                 return(false);
             }
             injector.AddModule(cur.TService, obj);
         }
     }
     return(true);
 }
示例#3
0
 // Pass through injector methods
 public object GetModule(Type type) => injector.GetModule(type);
示例#4
0
 public static bool TryGet(this IInjector injector, Type t, [NotNullWhen(true)] out object?obj)
 {
     obj = injector.GetModule(t);
     return(obj != null);
 }
示例#5
0
 public static bool TryGet <T>(this IInjector injector, [NotNullWhen(true)] out T?obj) where T : class
 {
     obj = injector.GetModule <T>();
     return(obj != null);
 }
示例#6
0
 public static T?GetModule <T>(this IInjector injector) where T : class
 {
     return((T?)injector.GetModule(typeof(T)));
 }
示例#7
0
 public bool TryGet(Type t, out object obj)
 {
     obj = dynamicObjects.GetModule(t);
     return(obj != null);
 }
 public static bool TryGet(this IInjector injector, Type t, out object obj)
 {
     obj = injector.GetModule(t);
     return(obj != null);
 }
 public static bool TryGet <T>(this IInjector injector, out T obj)
 {
     obj = injector.GetModule <T>();
     return(obj != null);
 }
示例#10
0
 public static T GetModule <T>(this IInjector injector)
 {
     return((T)injector.GetModule(typeof(T)));
 }