I got .NET Core application.
There are some long running REST API endpoints which returns status code ACCEPTED and then later the result by pooling a long runing asychronous job with GET.
The long running job generates a result including HATEOS links with absolute URL. The link needs to be really absolute at least because of unification of REST API of different products made by one company.
So the problem is that the backgorund jobs needs to access HTTP Context (host, schema) from those long running task to generate HATEOS.
The current design is following:
public async Task<ActionResult> Foo(CancellationToken cancellationToken)
{
IUriMaker uriMaker = _uriMakerProvider.CreateInScopeOfHttpContext();
return await _asyncOperationService.ExecuteSyncOrAsync(
ct => Task.FromResult(...),
async ct => longRunnignTask(ct)),
uriMaker, cancellationToken);
}
The _uriMakerProvider is injected using dependency injection and make copy of HttpContext propeties like host and schema.
The code works fine, I just don't like passing IUriMaker by 20 layers of abstration and increasing a coupling of the code which is not too much related to UriMaker. I cannot pass IUriMaker by DY, because it is already late in background thread and the HttpContext is no more available.
Is there a best practise which can solve this problem?
Aucun commentaire:
Enregistrer un commentaire