public static bool TryCreate(this IInjector injector, Type type, [NotNullWhen(true)] out object?obj) { var param = DependencyBuilder.GetContructorParam(type); if (param == null) { throw new ArgumentException("Invalid type, no constructors"); } var call = new object[param.Length]; for (int i = 0; i < param.Length; i++) { if (!injector.TryGet(param[i], out var dep)) { obj = default; return(false); } call[i] = dep; } obj = Activator.CreateInstance(type, call) ?? throw new ArgumentException("Activator didn't do his job..."); return(true); }
public Module(Type tService, Type tImplementation) { TService = tService; TImplementation = tImplementation; ConstructorParam = DependencyBuilder.GetContructorParam(TImplementation) ?? throw new ArgumentException("Invalid type"); }