Ejemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="Store"/> class.</summary>
        /// <param name="storages">Storages what values will be presisted to.</param>
        /// <param name="immutableValidator"><see cref="ImmutableValidator"/> used to validate immutablity of values.</param>
        /// <param name="serializableValidator"><see cref="SerializableValidator"/> used to validate serializability of values.</param>
        /// <param name="cache"><see cref="IStoreResultCache"/> used by store.</param>
        /// <param name="formatter"><see cref="IFormatProvider"/> used to serialize and deserialize values.</param>
        /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> is storages is null.</exception>
        /// <exception cref="ArgumentException">Throws <see cref="ArgumentException"/> if storage is empty or has null values.</exception>
        public Store(
            IEnumerable <IStorage> storages,
            ImmutableValidator immutableValidator       = null,
            SerializableValidator serializableValidator = null,
            IStoreResultCache cache = null,
            IFormatter formatter    = null)
        {
            if (storages == null)
            {
                throw new ArgumentNullException(nameof(storages));
            }

            this.storages = storages.ToArray();
            if (this.storages.Length == 0)
            {
                throw new ArgumentException("Did not contain any values.", nameof(storages));
            }

            if (this.storages.Any(s => s == null))
            {
                throw new ArgumentException("Contained a null value.", nameof(storages));
            }

            if (immutableValidator == null)
            {
                immutableValidator = new ImmutableValidator();
            }

            this.immutableValidator = immutableValidator;

            if (serializableValidator == null)
            {
                serializableValidator = new SerializableValidator();
            }

            this.serializableValidator = serializableValidator;

            if (cache == null)
            {
                cache = new StoreResultCache();
            }

            this.cache = cache;

            if (formatter == null)
            {
                formatter = new BinaryFormatter();
            }

            this.formatter = formatter;
        }
Ejemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="Store"/> class.</summary>
        /// <param name="storage">Storage what values will be presisted to.</param>
        /// <param name="immutableValidator"><see cref="ImmutableValidator"/> used to validate immutablity of values.</param>
        /// <param name="serializableValidator"><see cref="SerializableValidator"/> used to validate serializability of values.</param>
        /// <param name="cache"><see cref="IStoreResultCache"/> used by store.</param>
        /// <param name="formatter"><see cref="IFormatProvider"/> used to serialize and deserialize values.</param>
        /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> is storage is null.</exception>
        public Store(
            IStorage storage,
            ImmutableValidator immutableValidator       = null,
            SerializableValidator serializableValidator = null,
            IStoreResultCache cache = null,
            IFormatter formatter    = null)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            this.storages = new[] { storage };

            if (immutableValidator == null)
            {
                immutableValidator = new ImmutableValidator();
            }

            this.immutableValidator = immutableValidator;

            if (serializableValidator == null)
            {
                serializableValidator = new SerializableValidator();
            }

            this.serializableValidator = serializableValidator;

            if (cache == null)
            {
                cache = new StoreResultCache();
            }

            this.cache = cache;

            if (formatter == null)
            {
                formatter = new BinaryFormatter();
            }

            this.formatter = formatter;
        }