/// <summary> /// Adds an object with singleton lifetime for the specified key /// </summary> /// <typeparam name="TSrc">The type that will be used as a key</typeparam> /// <typeparam name="TTarg">The type of the object that will be held by the singleton lifetime container</typeparam> /// <param name="obj">Association container to which the addition is performed</param> /// <param name="val">The object that will be held by the singleton lifetime container</param> public static void AddSingleton <TSrc, TTarg>(this IDirectSingletonAssociationSupport <Type> obj, TTarg val) { Contract.Requires(obj != null); obj.AddSingleton(typeof(TSrc), (object)val); }
/// <summary> /// Attempts to add an object with singleton lifetime for the specified key /// </summary> /// <typeparam name="TSrc">The type that will be used as a key</typeparam> /// <typeparam name="TTarg">The type of the object that will be held by the singleton lifetime container</typeparam> /// <param name="obj">Association container to which the addition is performed</param> /// <param name="val">The object that will be held by the singleton lifetime container</param> /// <returns>True if the association was added successfully (that is AssociationContainer did not contained lifetime container with the same key); overwise false</returns> public static bool TryAddSingleton <TSrc, TTarg>(this IDirectSingletonAssociationSupport <Type> obj, TTarg val) { TurboContract.Requires(obj != null, conditionString: "obj != null"); return(obj.TryAddSingleton(typeof(TSrc), (object)val)); }