Skip to content

Add support for some additional lifecycle hooks #13734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dijitalmunky opened this issue Sep 5, 2019 · 2 comments
Closed

Add support for some additional lifecycle hooks #13734

dijitalmunky opened this issue Sep 5, 2019 · 2 comments
Labels
area-signalr Includes: SignalR clients and servers

Comments

@dijitalmunky
Copy link

We are writing a new application using signalR to perform updates and disperse updates on all of the business objects in our application. We were hoping to that like Mvc Controllers we could hook into before and after a method is invoked (i.e. OnActionExecuting() and OnActionExecuted()). However, there seems to be no way to do this in signalR.

Our use case for this is varied. The biggest 2 that come to mind are:

  1. Setting custom properties in a logging (or other) context. For example, the adding parameter values that were used to invoke the method.
  2. Audit logging. Are application has requirements for audit logging. We have implemented this in an "old school" way before by having a centralized class/method that can be injected/invoked.

Being able to hook into these two events would give us the advantage that the developer does not need to remember to call a central method every time an action is taken. This is something that we have had issues with before.

Ideally, 2 (or 3, if you want to support async) methods would be added to the base Hub class. The default implementation would do nothing, but they could be overridden to perform what we need:

  • OnActionExecuting(HubActionContext ctx) - invoked before a Hub method is invoked by the client.
  • OnActionExecuted(HubActionContext ctx) - invoked after a Hub method is invoked by the client.
  • OnActionExecutionAsync((HubActionContext ctx, ActionDelegate delegate) - invoked before the hub method is called. delegate that is called to continue execution.

HubActionContext would be similar to the current HubCallerContext with the following additional values:

  • Action - the Method for the action that is being invoked.
  • ActionArguments - the parameters for the action being invoked (similar to ActionExecutingContext.ActionArguments in the Microsoft.AspNetCore.Mvc.Filters namespace.
@mkArtakMSFT mkArtakMSFT added the area-signalr Includes: SignalR clients and servers label Sep 5, 2019
@BrennanConroy
Copy link
Member

Looks like you want the Hub Pipeline feature that we're considering for 5.0
See issue #5353

@dijitalmunky
Copy link
Author

Perfect, Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

3 participants