Server Events C# Client - get local service instance

Is there a way to get the “local” url of service stack in an adjacent (dependent) assembly? (ASP.NET host)

var client = new ServerEventsClient(
    "", channels:"home");

Within a service we can use the IServerEvents directly which is nice… but when we are buried way deep down in a call stack or running async it looks like it will be best to use a client, just can’t easily determine the URL. (well, it could be localhost but port # is variable)

other approach suggestions welcome. just trying to get server events to the local server to be broadcast to clients.

By “local” URL I’m assuming you mean the URL for the incoming request? This can vary per request and is only available at runtime as such the IRequest should be passed from base.Request in your Service to your dependencies, i.e. via parameters.

If you’re using ASP.NET you could access the IRequest from HostContext.TryGetCurrentRequest() which is just a wrapper around ASP.NET’s HttpContext.Current singleton.

I think the general challenge we have is trying to pass new types of context around as our codebase has grown larger and callstacks are very deep. We’ve solved by setting a static reference in the helper class during service calls in this case so we can easily send server events. Not optimal but will continue to refine.