コード例 #1
0
        internal static (TimeoutValue keepaliveCadence, bool useTransaction, bool useMultiplexing) GetOptions(Action <SqlConnectionOptionsBuilder>?optionsBuilder)
        {
            SqlConnectionOptionsBuilder?options;

            if (optionsBuilder != null)
            {
                options = new SqlConnectionOptionsBuilder();
                optionsBuilder(options);
            }
            else
            {
                options = null;
            }

            var keepaliveCadence = options?._keepaliveCadence ?? TimeSpan.FromMinutes(10);
            var useTransaction   = options?._useTransaction ?? false;
            var useMultiplexing  = options?._useMultiplexing ?? true;

            if (useMultiplexing && useTransaction)
            {
                throw new ArgumentException(nameof(UseTransaction) + ": is not compatible with " + nameof(UseMultiplexing));
            }

            return(keepaliveCadence, useTransaction, useMultiplexing);
        }
コード例 #2
0
        internal static IDbDistributedLock CreateInternalLock(string name, string connectionString, Action <SqlConnectionOptionsBuilder>?optionsBuilder)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var(keepaliveCadence, useTransaction, useMultiplexing) = SqlConnectionOptionsBuilder.GetOptions(optionsBuilder);

            if (useMultiplexing)
            {
                return(new OptimisticConnectionMultiplexingDbDistributedLock(name, connectionString, SqlMultiplexedConnectionLockPool.Instance, keepaliveCadence));
            }

            return(new DedicatedConnectionOrTransactionDbDistributedLock(name, () => new SqlDatabaseConnection(connectionString), useTransaction: useTransaction, keepaliveCadence));
        }