예제 #1
0
        private static IDbExecutionStrategy GetExecutionStrategy(
            DbConnection connection,
            DbProviderFactory providerFactory,
            string providerInvariantName = null)
        {
            var entityConnection = connection as EntityConnection;

            if (entityConnection != null)
            {
                connection = entityConnection.StoreConnection;
            }

            var dataSource = DbInterception.Dispatch.Connection.GetDataSource(connection, new DbInterceptionContext());

            // Using the type name of DbProviderFactory implementation instead of the provider invariant name for performance
            var cacheKey = new ExecutionStrategyKey(providerFactory.GetType().FullName, dataSource);

            var factory = _executionStrategyFactories.GetOrAdd(
                cacheKey,
                k =>
                DbConfiguration.DependencyResolver.GetService <Func <IDbExecutionStrategy> >(
                    new ExecutionStrategyKey(
                        providerInvariantName ?? DbConfiguration.DependencyResolver.GetService <IProviderInvariantName>(providerFactory).Name,
                        dataSource)));

            return(factory());
        }
        private static IDbExecutionStrategy GetExecutionStrategy(
            DbConnection connection,
            DbProviderFactory providerFactory,
            string providerInvariantName = null)
        {
            EntityConnection entityConnection = connection as EntityConnection;

            if (entityConnection != null)
            {
                connection = entityConnection.StoreConnection;
            }
            string dataSource        = DbInterception.Dispatch.Connection.GetDataSource(connection, new DbInterceptionContext());
            ExecutionStrategyKey key = new ExecutionStrategyKey(providerFactory.GetType().FullName, dataSource);

            return(DbProviderServices._executionStrategyFactories.GetOrAdd(key, (Func <ExecutionStrategyKey, Func <IDbExecutionStrategy> >)(k => DbConfiguration.DependencyResolver.GetService <Func <IDbExecutionStrategy> >((object)new ExecutionStrategyKey(providerInvariantName ?? DbConfiguration.DependencyResolver.GetService <IProviderInvariantName>((object)providerFactory).Name, dataSource))))());
        }
예제 #3
0
        /// <summary>
        /// If the given type is <see cref="T:System.Func`1" />, then this method will attempt
        /// to return the service to use, otherwise it will return <c>null</c>. When the given type is
        /// <see cref="T:System.Func`1" />, then the key is expected to be a <see cref="T:System.Data.Entity.Infrastructure.ExecutionStrategyKey" />.
        /// </summary>
        /// <param name="type">The service type to resolve.</param>
        /// <param name="key">A key used to make a determination of the service to return.</param>
        /// <returns>
        /// An <see cref="T:System.Func`1" />, or null.
        /// </returns>
        public object GetService(Type type, object key)
        {
            if (!(type == typeof(Func <TransactionHandler>)))
            {
                return((object)null);
            }
            ExecutionStrategyKey executionStrategyKey = key as ExecutionStrategyKey;

            if (executionStrategyKey == null)
            {
                throw new ArgumentException(Strings.DbDependencyResolver_InvalidKey((object)typeof(ExecutionStrategyKey).Name, (object)"Func<TransactionHandler>"));
            }
            if (this._providerInvariantName != null && !executionStrategyKey.ProviderInvariantName.Equals(this._providerInvariantName, StringComparison.Ordinal))
            {
                return((object)null);
            }
            if (this._serverName != null && !this._serverName.Equals(executionStrategyKey.ServerName, StringComparison.Ordinal))
            {
                return((object)null);
            }
            return((object)this._transactionHandlerFactory);
        }
        private static IExecutionStrategy GetExecutionStrategy(
            DbConnection connection,
            DbProviderFactory providerFactory)
        {
            var entityConnection = connection as EntityConnection;

            if (entityConnection != null)
            {
                connection = entityConnection.StoreConnection;
            }

            // Using the type name of DbProviderFactory implementation instead of the provider invariant name for performance
            var cacheKey = new ExecutionStrategyKey(providerFactory.GetType().FullName, connection.DataSource);

            var factory = _executionStrategyFactories.GetOrAdd(
                cacheKey,
                k =>
                DbConfiguration.GetService <Func <IExecutionStrategy> >(
                    new ExecutionStrategyKey(
                        DbConfiguration.GetService <IProviderInvariantName>(providerFactory).Name,
                        connection.DataSource)));

            return(factory());
        }