Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Late parameter binding #1049

Merged
merged 2 commits into from
Oct 30, 2017
Merged

Late parameter binding #1049

merged 2 commits into from
Oct 30, 2017

Conversation

moozzyk
Copy link
Contributor

@moozzyk moozzyk commented Oct 24, 2017

Soliciting early feedback.

{
get
{
if (_bindingError != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How bad is this?

@@ -8,13 +8,29 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
{
public class InvocationMessage : HubMessage
{
// Use ExceptionDispatchInfo ?
private readonly Exception _bindingError;
Copy link
Member

Choose a reason for hiding this comment

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

Yes use ExceptionDispatchInfo

@moozzyk moozzyk force-pushed the pawelka/lateparambinding branch from 327d672 to 72d1f7a Compare October 25, 2017 00:06
Storing exception thrown during parameter binding and rethrowing when the method is about to throw. This allows completing invocations with a HubException and keeping the connection open.
We will also no longer close the connection if parameters for client side methods cannot be bound. We will log and continue.

Fixes: #818

(Also fixing #1005 because I was just touching this line)
@moozzyk moozzyk force-pushed the pawelka/lateparambinding branch from 72d1f7a to 2e0d99f Compare October 25, 2017 00:17
@moozzyk moozzyk changed the title Late parameter binding - Prototype Late parameter binding Oct 25, 2017
@moozzyk
Copy link
Contributor Author

moozzyk commented Oct 25, 2017

Ready for review.

@@ -137,7 +137,7 @@ public static void IssueInvocation(this ILogger logger, string invocationId, str
{
if (logger.IsEnabled(LogLevel.Trace))
{
var argsList = string.Join(", ", args.Select(a => a.GetType().FullName));
var argsList = string.Join(", ", args.Select(a => a?.GetType().FullName?? "(null)"));
Copy link
Member

Choose a reason for hiding this comment

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

space after FullName

Copy link
Member

Choose a reason for hiding this comment

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

Add null check for args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't do because it never happens but I think it won't hurt either.


// TODO(anurse): We can add some DI magic here to allow users to provide their own serialization
// Related Bug: https://github.com/aspnet/SignalR/issues/261
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to keep this comment in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We allow setting serialization settings in HubOptions so this is covered (#261 is closed).

}
catch (Exception ex)
{
throw new FormatException("Error binding arguments. Make sure that types of the provided values match the types of the hub method being invoked.", ex);
Copy link
Member

Choose a reason for hiding this comment

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

"that the types"

if (parameterTypes.Length != argumentCount)
{
throw new FormatException(
$"Target method expects {parameterTypes.Length} arguments(s) but invocation has {argumentCount} argument(s).");
$"Invocation provides {argumentCount} argument(s) but target expects {parameterTypes.Length}.");
Copy link
Member

Choose a reason for hiding this comment

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

Do we log on the server for any binding failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - it now fails when we are invoking the method so it is treated as any other hub method invocation error

@@ -556,7 +556,7 @@ public class RedisExcludeClientsMessage : InvocationMessage
public IReadOnlyList<string> ExcludedIds;

public RedisExcludeClientsMessage(string invocationId, bool nonBlocking, string target, IReadOnlyList<string> excludedIds, params object[] arguments)
: base(invocationId, nonBlocking, target, arguments)
: base(invocationId, nonBlocking, target, null, arguments)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't hurt to use named params here

@@ -136,7 +136,7 @@ public Task<string> SendInvocationAsync(string methodName, params object[] args)
public Task<string> SendInvocationAsync(string methodName, bool nonBlocking, params object[] args)
{
var invocationId = GetInvocationId();
return SendHubMessageAsync(new InvocationMessage(invocationId, nonBlocking, methodName, args));
return SendHubMessageAsync(new InvocationMessage(invocationId, nonBlocking, methodName, null, args));
Copy link
Member

Choose a reason for hiding this comment

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

named param

@moozzyk moozzyk merged commit 18f770e into dev Oct 30, 2017
@moozzyk moozzyk deleted the pawelka/lateparambinding branch November 14, 2017 18:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants