Fix ResolveSingle not awaited

pull/4/head
ocm-tompit 2 years ago
parent 6653fd2768
commit ab1ee48396

@ -35,7 +35,7 @@ internal sealed class ConnectionProvider : IConnectionProvider, IAsyncDisposable
if (TransactionService.State == MiddlewareTransactionState.Completed) if (TransactionService.State == MiddlewareTransactionState.Completed)
Mode = StorageConnectionMode.Isolated; Mode = StorageConnectionMode.Isolated;
return args is ISchemaSynchronizationContext context ? ResolveSingle(context) : await ResolveMultiple<TEntity>(args); return args is ISchemaSynchronizationContext context ? await ResolveSingle(context) : await ResolveMultiple<TEntity>(args);
} }
/// <summary> /// <summary>
/// This method is called if the supplied arguments already provided connection type on which they will perform operations. /// This method is called if the supplied arguments already provided connection type on which they will perform operations.
@ -48,9 +48,9 @@ internal sealed class ConnectionProvider : IConnectionProvider, IAsyncDisposable
/// <param name="behavior"></param> /// <param name="behavior"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NullReferenceException"></exception> /// <exception cref="NullReferenceException"></exception>
private ImmutableList<IStorageConnection> ResolveSingle(ISchemaSynchronizationContext args) private async Task<ImmutableList<IStorageConnection>> ResolveSingle(ISchemaSynchronizationContext args)
{ {
return new List<IStorageConnection> { EnsureConnection(args.ConnectionType, args.ConnectionString) }.ToImmutableList(); return new List<IStorageConnection> { await EnsureConnection(args.ConnectionType, args.ConnectionString) }.ToImmutableList();
} }
private async Task<ImmutableList<IStorageConnection>> ResolveMultiple<TEntity>(StorageContextArgs args) private async Task<ImmutableList<IStorageConnection>> ResolveMultiple<TEntity>(StorageContextArgs args)
@ -76,7 +76,7 @@ internal sealed class ConnectionProvider : IConnectionProvider, IAsyncDisposable
/* /*
* Default connection is always used regardless of sharding support * Default connection is always used regardless of sharding support
*/ */
EnsureConnection(connectionMiddleware.ConnectionType, connectionMiddleware.DefaultConnectionString) await EnsureConnection(connectionMiddleware.ConnectionType, connectionMiddleware.DefaultConnectionString)
}; };
if (shardingMiddleware is not null) if (shardingMiddleware is not null)
@ -92,14 +92,14 @@ internal sealed class ConnectionProvider : IConnectionProvider, IAsyncDisposable
if (Type.GetType(node.ConnectionType) is not Type connectionType) if (Type.GetType(node.ConnectionType) is not Type connectionType)
throw new NullReferenceException(node.ConnectionType); throw new NullReferenceException(node.ConnectionType);
result.Add(EnsureConnection(connectionType, node.ConnectionString)); result.Add(await EnsureConnection(connectionType, node.ConnectionString));
} }
} }
return result.ToImmutableList(); return result.ToImmutableList();
} }
private IStorageConnection EnsureConnection(Type connectionType, string connectionString) private async Task<IStorageConnection> EnsureConnection(Type connectionType, string connectionString)
{ {
if (Mode == StorageConnectionMode.Shared if (Mode == StorageConnectionMode.Shared
&& Connections.FirstOrDefault(f => f.GetType() == connectionType && Connections.FirstOrDefault(f => f.GetType() == connectionType
@ -108,15 +108,15 @@ internal sealed class ConnectionProvider : IConnectionProvider, IAsyncDisposable
return existing; return existing;
} }
else else
return CreateConnection(connectionType, connectionString, Mode); return await CreateConnection(connectionType, connectionString, Mode);
} }
private IStorageConnection CreateConnection(Type connectionType, string connectionString, StorageConnectionMode behavior) private async Task<IStorageConnection> CreateConnection(Type connectionType, string connectionString, StorageConnectionMode behavior)
{ {
if (Context.GetService(connectionType) is not IStorageConnection newConnection) if (Context.GetService(connectionType) is not IStorageConnection newConnection)
throw new NullReferenceException(connectionType.Name); throw new NullReferenceException(connectionType.Name);
newConnection.Initialize(new StorageConnectionArgs(connectionString, behavior)); await newConnection.Initialize(new StorageConnectionArgs(connectionString, behavior));
if (behavior == StorageConnectionMode.Shared) if (behavior == StorageConnectionMode.Shared)
Connections.Add(newConnection); Connections.Add(newConnection);

Loading…
Cancel
Save