Remove logger factory requirement from HubConnection (#238)

This commit is contained in:
Mikael Mengistu 2017-02-28 10:48:45 -08:00 committed by GitHub
parent af5e7da478
commit c1a4b25a66
6 changed files with 21 additions and 18 deletions

View File

@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
using Microsoft.AspNetCore.Sockets.Client; using Microsoft.AspNetCore.Sockets.Client;
using Microsoft.AspNetCore.Sockets.Client.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.SignalR.Client namespace Microsoft.AspNetCore.SignalR.Client
@ -45,29 +46,29 @@ namespace Microsoft.AspNetCore.SignalR.Client
remove { _connection.Closed -= value; } remove { _connection.Closed -= value; }
} }
public HubConnection(Uri url, IInvocationAdapter adapter)
: this(new Connection(url), adapter, null)
{ }
public HubConnection(Uri url)
: this(new Connection(url), new JsonNetInvocationAdapter(), null)
{ }
public HubConnection(Uri url, IInvocationAdapter adapter, ILoggerFactory loggerFactory) public HubConnection(Uri url, IInvocationAdapter adapter, ILoggerFactory loggerFactory)
: this(new Connection(url, loggerFactory), adapter, loggerFactory) : this(new Connection(url, loggerFactory), adapter, loggerFactory)
{ } { }
public HubConnection(IConnection connection, IInvocationAdapter adapter, ILoggerFactory loggerFactory) public HubConnection(IConnection connection, IInvocationAdapter adapter, ILoggerFactory loggerFactory)
{ {
// TODO: loggerFactory shouldn't be required
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
if (connection == null) if (connection == null)
{ {
throw new ArgumentNullException(nameof(connection)); throw new ArgumentNullException(nameof(connection));
} }
_connection = connection; _connection = connection;
_binder = new HubBinder(this); _binder = new HubBinder(this);
_adapter = adapter; _adapter = adapter;
_logger = loggerFactory.CreateLogger<HubConnection>(); _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<HubConnection>();
_connection.Received += OnDataReceived; _connection.Received += OnDataReceived;
_connection.Closed += Shutdown; _connection.Closed += Shutdown;
} }

View File

@ -7,6 +7,7 @@ using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading.Tasks.Channels; using System.Threading.Tasks.Channels;
using Microsoft.AspNetCore.Sockets.Client.Internal;
using Microsoft.AspNetCore.Sockets.Internal; using Microsoft.AspNetCore.Sockets.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -4,9 +4,9 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
namespace Microsoft.AspNetCore.Sockets.Client namespace Microsoft.AspNetCore.Sockets.Client.Internal
{ {
internal class NullLoggerFactory : ILoggerFactory public class NullLoggerFactory : ILoggerFactory
{ {
public static readonly ILoggerFactory Instance = new NullLoggerFactory(); public static readonly ILoggerFactory Instance = new NullLoggerFactory();

View File

@ -9,6 +9,7 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Sockets.Client.Internal;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.Sockets.Client
public LongPollingTransport(HttpClient httpClient, ILoggerFactory loggerFactory) public LongPollingTransport(HttpClient httpClient, ILoggerFactory loggerFactory)
{ {
_httpClient = httpClient; _httpClient = httpClient;
_logger = loggerFactory.CreateLogger<LongPollingTransport>(); _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<LongPollingTransport>();
} }
public Task StartAsync(Uri url, IChannelConnection<Message> application) public Task StartAsync(Uri url, IChannelConnection<Message> application)

View File

@ -2,13 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.IO.Pipelines; using System.Diagnostics;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Sockets.Client.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace Microsoft.AspNetCore.Sockets.Client namespace Microsoft.AspNetCore.Sockets.Client
{ {

View File

@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
using (var httpClient = _testServer.CreateClient()) using (var httpClient = _testServer.CreateClient())
{ {
var transport = new LongPollingTransport(httpClient, loggerFactory); var transport = new LongPollingTransport(httpClient, loggerFactory);
var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter(), loggerFactory); var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter());
try try
{ {
await connection.StartAsync(transport, httpClient); await connection.StartAsync(transport, httpClient);
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
using (var httpClient = _testServer.CreateClient()) using (var httpClient = _testServer.CreateClient())
{ {
var transport = new LongPollingTransport(httpClient, loggerFactory); var transport = new LongPollingTransport(httpClient, loggerFactory);
var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter(), loggerFactory); var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter());
try try
{ {
await connection.StartAsync(transport, httpClient); await connection.StartAsync(transport, httpClient);
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
using (var httpClient = _testServer.CreateClient()) using (var httpClient = _testServer.CreateClient())
{ {
var transport = new LongPollingTransport(httpClient, loggerFactory); var transport = new LongPollingTransport(httpClient, loggerFactory);
var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter(), loggerFactory); var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter());
try try
{ {
await connection.StartAsync(transport, httpClient); await connection.StartAsync(transport, httpClient);
@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
using (var httpClient = _testServer.CreateClient()) using (var httpClient = _testServer.CreateClient())
{ {
var transport = new LongPollingTransport(httpClient, loggerFactory); var transport = new LongPollingTransport(httpClient, loggerFactory);
var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter(), loggerFactory); var connection = new HubConnection(new Uri("http://test/hubs"), new JsonNetInvocationAdapter());
try try
{ {
await connection.StartAsync(transport, httpClient); await connection.StartAsync(transport, httpClient);