Resolving Service vs Injecting Service

Hello,

I am currently in a situation where I have to use one service of mine into another.
I have two ways to do it

  1. HostContext.Resolve<>
  2. Injecting service in constructor.

Along with using service I want to pass the IRequest as well to the resolved service as I want to send the same session across.

So I came with two ways,
First to use HostContext.Resolve<>

private void CallBaseService()
{
    var baseService = HostContext.Resolve<BaseServices>();
    baseService.Request = Request;
   // call function from base service.
}

Second,
Inject in constructor and then use it.

private readonly _baseService = BaseService;

constructor(BaseService baseService)
{
      _baseService = baseService;
}

// call the service in a function
private void CallBaseService()
{
     _baseService.Request = Request;
     // call function from baseService
}

Which would be most ideal way to do this?

Check out the Service Gateway docs, the recommended way to call another Service is to the Service Gateway to send a Request DTO.

Alternative solutions is to use the ResolveService base method to resolve another Service from the IOC which will also inject Request Context:

using var orderService = base.ResolveService<OrderService>();