If you’re unsure how to resolve a Service dependency you can look at how the Service class does it, i.e:
private IServiceGateway gateway;
public virtual IServiceGateway Gateway => gateway ??
(gateway = HostContext.AppHost.GetServiceGateway(Request));
Basically you’ll need access to the current IRequest
and resolve it from AppHost.GetServiceGateway(Request)
.
You can use HostContext.TryGetRequest()
to resolve an IRequest
but that only works in ASP.NET Hosts so I’d advise against it.
For any dependencies that require access to the current IRequest
(which is only available during the scope of a Current Request) I recommend passing it in as a param to the dependency, e.g:
public class MyServices : Service
{
public IMyDep MyDep { get; set; }
public object Any(MyRequest request) => MyDep.MyMethod(Gateway, request.Arg);
}