Skip to content

Conversation

BrennanConroy
Copy link
Member

Fixes #34843

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Aug 6, 2021
@@ -233,7 +233,7 @@ public HubConnection(IConnectionFactory connectionFactory, IHubProtocol protocol
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None" />.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous start.</returns>
public async Task StartAsync(CancellationToken cancellationToken = default)
public virtual async Task StartAsync(CancellationToken cancellationToken = default)
{
CheckDisposed();
using (_logger.BeginScope(_logScope))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logs in the override method won't have the log scope. Is it important?

How about adding new virtual methods which are already wrapped in the log scope?

public async Task StartAsync(CancellationToken cancellationToken = default)
{  
    using (_logger.BeginScope(_logScope))
    {
        await NewMethodStartAsync(cancellationToken);
    }
}

public virtual async Task NewMethodStartAsync(CancellationToken cancellationToken = default)
{
    CheckDisposed();
    await StartAsyncInner(cancellationToken).ForceAsync();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is to much ceremony for what we're trying to achieve. This is about testability, not about being able to put custom code into our logging scopes. If you want to create an outer scope for your override, you can still do that.

@BrennanConroy BrennanConroy merged commit 3f62031 into main Aug 11, 2021
@BrennanConroy BrennanConroy deleted the brecon/virtual branch August 11, 2021 03:58
@ghost ghost added this to the 6.0-rc1 milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make HubConnection more testable
3 participants