How to get schema and hostname of the app host


I’m using IOC to inject business logic implementation into service class. The business logic has to invoke another application hosted in the same machine. I’m looking to retrieve the hostname and schema of the application host when a business logic is initialized. Please, advise if it can be implemented.

public class MyService : Service
  public IMyBusinessLogic BL {get; set;}

 . . .

public class MyBusinessLogicImpl : IMyBusinessLogic
  private string rootUrl;

  public MyBusinessLogicImpl()
    // get root URL of the AppHostBase.Instance 

You need access to the current IRequest in order to work out what the baseUrl for that particular request is, i.e. in your Service you can get it with:

 var baseUrl = base.Request.BaseUrl();

If you’re hosted in ASP.NET (i.e. your AppHost inherits AppHostBase) you can access the current Request via ASP.NET Singleton:

var baseUrl = HostContext.GetCurrentRequest().GetBaseUrl();

Otherwise you can force your Services to use a specific BaseUrl by specifying it in your AppHost, e.g:

SetConfig(new HostConfig { 
    WebHostUrl = baseUrl,

And access this anywhere via the Singleton:

var baseUrl = HostContext.Config.WebHostUrl;