Skip to content

ScopedServiceProvider should throw helpful exception when outside HttpContext #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Jul 31, 2018 · 0 comments

Comments

@jaredcnance
Copy link
Contributor

This often leads to exceptions like:

System.NullReferenceException : Object reference not set to an instance of an object.
---- The following constructor parameters did not have matching fixture data: TestFixture`1 fixture
Stack Trace:

----- Inner Stack Trace #1 (System.NullReferenceException) -----
   at JsonApiDotNetCore.Services.RequestScopedServiceProvider..ctor(IHttpContextAccessor httpContextAccessor)

public RequestScopedServiceProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
/// <inheritdoc />
public object GetService(Type serviceType) => _httpContextAccessor.HttpContext.RequestServices.GetService(serviceType);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant