/// <summary> /// Method to register a platform specific class to interface type.<br/> /// Calling this method before initializing, will call Init(false) automatically<br/> /// Only use this method if the class does NOT have 'Implements' attribute /// </summary> /// <typeparam name="TInterface">The interface that is implemented, and also the retrievement-key</typeparam> /// <typeparam name="TImplentor">The class that implements the interface</typeparam> public static bool Register <TInterface, TImplentor>(bool initOnRegister = true, bool singleInstance = true) where TImplentor : class, TInterface, new() { if (!_initialized) { Init(false); } if (_map.ContainsKey(typeof(TInterface))) { throw new DependencyManagerException($"{typeof(TInterface).Name} already registered!"); } IImplementor impl; if (!singleInstance) { impl = new FactoryImpl(typeof(TImplentor)); } else if (initOnRegister) { impl = new EagerSingletonImpl(new TImplentor()); } else { impl = new LazySingletonImpl(typeof(TImplentor)); } return(_map.TryAdd(typeof(TInterface), impl)); }
public static T CreateInstance <TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) => FactoryImpl <T, TArg0, TArg1, TArg2, TArg3, TArg4, TArg5, TArg6> .Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
public static T CreateInstance() => FactoryImpl <T> .Create();
public static T CreateInstance <TArg0, TArg1, TArg2, TArg3, TArg4>(TArg0 arg0, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4) => FactoryImpl <T, TArg0, TArg1, TArg2, TArg3, TArg4> .Create(arg0, arg1, arg2, arg3, arg4);
public static T CreateInstance <TArg0, TArg1, TArg2>(TArg0 arg0, TArg1 arg1, TArg2 arg2) => FactoryImpl <T, TArg0, TArg1, TArg2> .Create(arg0, arg1, arg2);
public static T CreateInstance <TArg0, TArg1>(TArg0 arg0, TArg1 arg1) => FactoryImpl <T, TArg0, TArg1> .Create(arg0, arg1);
public static T CreateInstance <TArg0>(TArg0 arg0) => FactoryImpl <T, TArg0> .Create(arg0);
static FactoryImpl() { _instance = new FactoryImpl(); }