Skip to content

ScopedServiceProvider should throw helpful exception when outside HttpContext #362

Closed
@jaredcnance

Description

@jaredcnance

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions