> System.InvalidCastException: 'Unable to cast object of type 'AsyncStateMachineBox`1[System.IDisposable,Steeltoe.Connectors.RabbitMQ.RabbitMQServiceCollectionExtensions+<CreateConnectionAsync>d__5]' to type 'RabbitMQ.Client.IConnection'.'
This happened because the connect callback returned a `Task<IConnection>`, whereas the connector is registered in the service container with `IConnection`. There are two solutions:
1. Change the service registration from `ConnectorFactory<RabbitMQOptions, IConnection>` to `ConnectorFactory<RabbitMQOptions, Task<IConnection>>`, such that the call to `connectorFactory.Get().GetConnection()` needs to be awaited.
2. Stick with the current API and synchronously wait for the task to complete before returning it.
This PR implements solution 2, because that doesn't require breaking the public API.
I'm also unsure whether it's safe when the task is awaited concurrently.
Description
Fixed crash during RabbitMQ connect:
This happened because the connect callback returned a
Task<IConnection>, whereas the connector is registered in the service container withIConnection. There are two solutions:ConnectorFactory<RabbitMQOptions, IConnection>toConnectorFactory<RabbitMQOptions, Task<IConnection>>, such that the call toconnectorFactory.Get().GetConnection()needs to be awaited.This PR implements solution 2, because that doesn't require breaking the public API. I'm also unsure whether it's safe when the task is awaited concurrently.
Quality checklist
If your change affects other repositories, such as Documentation, Samples and/or MainSite, add linked PRs here.