Is there a recommend way to retrieve the servicename from within a plugin?
Currently only have the IAppHost interface passed in and the ServiceName is declared on the ServiceStackHost. Currently casting which works but wondering if I missing something.
private void MyPluginHandler(IAppHost host)
{
var serviceName = ((ServiceStackHost)host).ServiceName;
}
Is there a reliable method (self or iis hosted) to obtain the http://url:port/path that the AppHost is running on from the appHost.AfterInitCallbacks?
Currently just passing this in via the constructor to the apphost
public override void Configure(Container container)
{
SetConfig(new HostConfig { WebHostUrl = selfhostUrlFieldSetViaConstructor });
AfterInitCallbacks.Add(host =>
{
// how to get http://uri:port/path of service?
var usingThis = host.Config.WebHostUrl;
var path = host.Config.HandlerFactoryPath;
});
}
No, the url where ServiceStack is called from is only available within the context of a HTTP request at runtime.
You can get the path where ServiceStack is mounted at Config.HandlerFactoryPath but not the url unless you explicitly specify it yourself with Config.WebHostUrl, but you wont be able to predict what the url is at StartUp.
For self-hosting you can get the prefixes where HttpListener is mounted at from the Listener.Prefixes collection but this doesn’t always equate to a url since it’s typically started with a wild card, e.g. http://*:8080 and you’ll only know what url your service gets called with at runtime.