File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/JsonApiDotNetCore/Services Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1+ using JsonApiDotNetCore . Internal ;
12using Microsoft . AspNetCore . Http ;
23using System ;
34
@@ -23,6 +24,16 @@ public RequestScopedServiceProvider(IHttpContextAccessor httpContextAccessor)
2324 }
2425
2526 /// <inheritdoc />
26- public object GetService ( Type serviceType ) => _httpContextAccessor . HttpContext . RequestServices . GetService ( serviceType ) ;
27+ public object GetService ( Type serviceType )
28+ {
29+ if ( _httpContextAccessor . HttpContext == null )
30+ throw new JsonApiException ( 500 ,
31+ "Cannot resolve scoped service outside the context of an HTTP Request." ,
32+ detail : "If you are hitting this error in automated tests, you should instead inject your own "
33+ + "IScopedServiceProvider implementation. See the GitHub repository for how we do this internally. "
34+ + "https://github.com/json-api-dotnet/JsonApiDotNetCore/search?q=TestScopedServiceProvider&unscoped_q=TestScopedServiceProvider" ) ;
35+
36+ return _httpContextAccessor . HttpContext . RequestServices . GetService ( serviceType ) ;
37+ }
2738 }
2839}
You can’t perform that action at this time.
0 commit comments