Skip to content

Lazy named services are resolved incorrectly #606

@kemsky

Description

@kemsky
// Register Bar service without providing a name:
serviceContainer.Register<Bar>();

// The following code injects Lazy<Bar> but it should fail because there is no service Bar with name "some-name":
Consumer ([Inject("some-name")] Lazy<Bar> lazyBar) {
     // this also does not fail:
     Console.WriteLine(lazyBar.Value.ToString());
}

Inject attribute is effectively ignored when Lazy<> is used. According to the source code service name is not used when Lazy<> is requested.

I'm trying to use named services to create Lazy<HttpClient> automatically via RegisterFallback but this bug prevents RegisterFallback from running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions