Exemple #1
0
 /// <summary>
 /// Determines whether the required dependency has been registered
 /// </summary>
 /// <typeparam name="TAbstract">Type of the singleton or dependency</typeparam>
 /// <remarks>
 /// Services will be loaded if exists in this order:
 /// - Initialized singletons
 /// - Uninitialized singletons
 /// - Transients
 /// </remarks>
 public bool HasRequiredDependency(Type serviceType)
 {
     if (InitializedSingletons.ContainsKey(serviceType))
     {
         return(true);
     }
     else if (RegisteredSingletons.ContainsKey(serviceType))
     {
         return(true);
     }
     else if (RegisteredTransients.ContainsKey(serviceType))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
 /// <summary>
 /// Gets a registered singleton or transient dependency, or null if the dependency could not be found
 /// </summary>
 /// <typeparam name="TAbstract">Type of the singleton or dependency</typeparam>
 /// <remarks>
 /// Services will be loaded if exists in this order:
 /// - Initialized singletons
 /// - Uninitialized singletons
 /// - Transients
 /// </remarks>
 public object GetRequiredDependency(Type serviceType)
 {
     if (InitializedSingletons.ContainsKey(serviceType))
     {
         return(InitializedSingletons[serviceType]);
     }
     else if (RegisteredSingletons.ContainsKey(serviceType))
     {
         var instance = RegisteredSingletons[serviceType].Invoke(this);
         InitializedSingletons.Add(serviceType, instance);
         return(instance);
     }
     else if (RegisteredTransients.ContainsKey(serviceType))
     {
         return(RegisteredTransients[serviceType].Invoke(this));
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
 /// <summary>
 /// Registers a type that can be provided to dynamically-created objects in their constructor, created every time it is requested.
 /// </summary>
 /// <typeparam name="T">Type to be provided to dynamically-created objects</typeparam>
 /// <param name="constructor">Function that creates the type to be provided</param>
 public void AddTransientDependency <T>(Func <PluginManager, T> constructor) where T : class
 {
     RegisteredTransients.Add(typeof(T), p => constructor(p));
 }