/// <summary> /// Returns true if the given singletonInstanceBehavior is one of the values that allows a caller to assign the Instance directly. /// <para/>AutoConstructIfNeeded, ManuallyAssign_MayBeNull, ManuallyAssign_MustBeNonNull /// </summary> public static bool InstanceCanBeManuallyAssignedBehavior(this SingletonInstanceBehavior singletonInstanceBehavior) { return(singletonInstanceBehavior == SingletonInstanceBehavior.AutoConstructIfNeeded || singletonInstanceBehavior == SingletonInstanceBehavior.ManuallyAssign_MayBeNull || singletonInstanceBehavior == SingletonInstanceBehavior.ManuallyAssign_MustBeNonNull ); }
/// <summary> /// Base constructor. Constructs a SingletonHelperBase with client given behavior and InstanceConstructionDelegate. /// Resulting SingletonHelper may be used as IDisposable and supports use with SingletonObjectTypes that are either IDisposable or not. /// </summary> /// <param name="behavior">Defines the Instance property construction and use behavior: AutoConsruct, ManuallyAssign_MustBeNonNull or ManuallyAssign_MayBeNull</param> /// <param name="instanceConstructionDelegate">Gives the delegate that will be invoked to construct the instance object if/when that is required. Must not be null if the given behavior may AutoConstruct the instance.</param> /// <exception cref="SingletonException">thrown if instanceConstructionDelegate is null and the given behavior may attempt to AutoConstruct the instance.</exception> public SingletonHelperBase(SingletonInstanceBehavior behavior, InstanceConstructionDelegate instanceConstructionDelegate) { Behavior = behavior; this.instanceConstructionDelegate = instanceConstructionDelegate; if (instanceConstructionDelegate == null && behavior.IsAutoConstructBehavior()) { throw new SingletonException("Attempt to use a null instanceConstructionDelegate with {0} behavior".CheckedFormat(behavior)); } }
/// <summary> /// Base constructor. Constructs a SingletonHelper with client given behavior. /// Resulting SingletonHelper may be used as IDisposable and supports use with SingletonObjectTypes that are either IDisposable or not. /// </summary> /// <param name="behavior">Defines the Instance property construction and use behavior: AutoConsruct, ManuallyAssign_MustBeNonNull or ManuallyAssign_MayBeNull</param> public SingletonHelper(SingletonInstanceBehavior behavior) : base(behavior) { }
/// <summary> /// Returns true if the singletonInstanceBehavior allows the Instance to be set to null. /// <para/>ManuallyAssign_MayBeNull, AutoConstructIfNeeded /// </summary> public static bool DoesBehaviorPermitInstanceToBeSetToNull(this SingletonInstanceBehavior singletonInstanceBehavior) { return(singletonInstanceBehavior == SingletonInstanceBehavior.ManuallyAssign_MayBeNull || singletonInstanceBehavior == SingletonInstanceBehavior.AutoConstructIfNeeded); }
/// <summary> /// Returns true if the singletonInstanceBehavior allows the Instance getter to return null. /// <para/>ManuallyAssign_MayBeNull /// </summary> public static bool DoesBehaviorPermitInstanceGetterToReturnNull(this SingletonInstanceBehavior singletonInstanceBehavior) { return(singletonInstanceBehavior == SingletonInstanceBehavior.ManuallyAssign_MayBeNull); }
/// <summary> /// Returns true if the given singletonInstanceBehavior that may attempt to construct the instance when first required. /// <para/>AutoConstruct, AutoConstructIfNeeded /// </summary> public static bool IsAutoConstructBehavior(this SingletonInstanceBehavior singletonInstanceBehavior) { return(singletonInstanceBehavior == SingletonInstanceBehavior.AutoConstruct || singletonInstanceBehavior == SingletonInstanceBehavior.AutoConstructIfNeeded ); }