Skip to content

Resolving concrete service type does not work in Middleware.Invoke #37

@toha73

Description

@toha73

Trying to resolve a concrete type with dependencies does not work when I pass the IServiceProvicer in as an argument to the Invoke-method. However, if I get the service via Container first, and then try to resolve with IServiceProvider it works:

public async Task Invoke(HttpContext context, IServiceProvider serviceProvider)
{
    var myService1 = serviceProvider.GetService(typeof(MyService));  // == null
    var myService2 = Startup.Container.GetInstance<MyService>();     // != null
    var myService2 = serviceProvider.GetService(typeof(MyService));  // != null
   ...

EDIT: This is for .NET Core 2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions