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
- HostContext.Resolve<>
- 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?