예제 #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);
 }
예제 #8
0
 public static bool TryGet(this IInjector injector, Type t, out object obj)
 {
     obj = injector.GetModule(t);
     return(obj != null);
 }
예제 #9
0
 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)));
 }