/// <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> /// Default constructor. Constructs a SingletonHelperBase with AutoConstruct behavior and client given InstanceConstructionDelegate. /// Resulting SingletonHelper may be used as IDisposable and supports use with SingletonObjectTypes that are either IDisposable or not. /// </summary> /// <param name="instanceConstructionDelegate">Gives the delegate that will be invoked to construct the instance object if/when that is required</param> public SingletonHelperBase(InstanceConstructionDelegate instanceConstructionDelegate) : this(SingletonInstanceBehavior.AutoConstruct, instanceConstructionDelegate) { }