Пример #1
0
        /// <summary>
        /// Create a mutable resource vault to protect a mutable resource
        /// </summary>
        /// <param name="mutableResourceCreator">A delegate that will construct A NEW RESOURCE of type T.  It should NOT
        /// return an existing stringbuilder, it should simply be a delegate to the CTOR.  The vault can only isolate
        /// that which doesn't exist anywhere yet.</param>
        /// <param name="defaultTimeout">the default timeout</param>
        /// <returns>a an object of this type that stores the resource produced by <paramref name="mutableResourceCreator"/> and has a
        /// default timeout of <paramref name="defaultTimeout"/></returns>
        /// <exception cref="ArgumentNullException"><paramref name="mutableResourceCreator"/> was null</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="defaultTimeout"/> was not positive.</exception>
        public static MutableResourceVault <T> CreateAtomicMutableResourceVault([NotNull] Func <T> mutableResourceCreator,
                                                                                TimeSpan defaultTimeout)
        {
            IMutableResourceVaultFactory <MutableResourceVault <T>, T> factory =
                MutableResourceVaultFactory <MutableResourceVault <T> > .CreateFactory();

            return(factory.CreateMutableResourceVault(mutableResourceCreator, defaultTimeout,
                                                      () => new MutableResourceVault <T>(defaultTimeout)));
        }
Пример #2
0
            /// <summary>
            /// Add the following factory method to the nested class
            /// </summary>
            /// <param name="defaultTimeOut">the default time-out</param>
            /// <param name="resourceGen">a function to generate the initial value of the protected resource</param>
            /// <returns>An implementation of <see cref="CustomizableAtomicMutableResourceVault{T}"/> that your custom class
            /// (here <see cref="StringBuilderVault"/>) will delegate to.</returns>
            internal static LsfvImpl CreateLsvImpl(TimeSpan defaultTimeOut,
                                                   [NotNull] Func <LaundryStatusFlags> resourceGen)
            {
                MutableResourceVaultFactory <LsfvImpl> factory =
                    LsvImplFactory.CreateLsfFactory();

                return(factory.CreateMutableResourceVault(
                           resourceGen ?? throw new ArgumentNullException(nameof(resourceGen)), defaultTimeOut,
                           () => new LsfvImpl(defaultTimeOut)));
            }
Пример #3
0
 public static bool SupplyAlternateFactory([NotNull] MutableResourceVaultFactory <T> alternate) =>
 TheMrvFactory.SetToNonDefaultValue(alternate ?? throw new ArgumentNullException(nameof(alternate)));