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); }
/// <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); }
// Pass through injector methods public object GetModule(Type type) => injector.GetModule(type);
public static bool TryGet(this IInjector injector, Type t, [NotNullWhen(true)] out object?obj) { obj = injector.GetModule(t); return(obj != null); }
public static bool TryGet <T>(this IInjector injector, [NotNullWhen(true)] out T?obj) where T : class { obj = injector.GetModule <T>(); return(obj != null); }
public static T?GetModule <T>(this IInjector injector) where T : class { return((T?)injector.GetModule(typeof(T))); }
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); }
public static T GetModule <T>(this IInjector injector) { return((T)injector.GetModule(typeof(T))); }