msr
✅ SignalR Core Disconnect on Navigate
I'm trying to listen for when a user disconnects so I can remove them from a game lobby.
It seems like OnDisconnectedAsync is called when a user closes the tab/window. But it is not called when they navigate away from the page.
I've tested on Chrome and Edge, and similar behavior. Tested on an older version of the app (also using ASP.NET Core SignalR Core), same behavior.
Is there any way to enforce that it should be called on navigate? I would assume the server should be alerted because the websocket connection would close...
170 replies
MediatR IPipelineBehavior for reacting to large set of requests (+ Result return type)
I have a system where I'm trying to migrate our existing closed IPipelineBehaviors to an open generic IPipelineBehavior (for ease of wiring up in the DI container).
We have a finite list of requests that we care about, and if the underlying handler has succeeded, we generate an event and shoot it off to a message broker.
Currently this IPipelineBehavior is listening to say... 20-25 requests. We are wiring it up with some black reflection magic. We would love to be able to convert this to an open generic and pattern match on the request within the pipeline:
The problem is we aren't using exceptions for control flow, we are using result types (
Result<T, TException>
). When using the closed generic implementation, we can type the IPipelineBehavior
to be constrained as
The above implementation lets us check if the result of the RequestHandlerDelegate<Result<TResponse, Error>>
is an Error
, at which point we don't send the event off.
Once we convert the event notifier to be an open generic, we lose the context of a Result<T, E>
, and suddenly we have no idea if the handler completed successfully or not.
I'd love to know of some solutions that don't necessarily include having to manually implement 25 interfaces, and ideally don't require heavy reflection, as this behavior will be ran quite a lot. What is the idiomatic solution to this problem?41 replies