Skip to content

Optional dependency @inject for Blazor #7653

Open
@stefanloerwald

Description

Is your feature request related to a problem? Please describe.

In some situations, services can be optional. For regular classes we can write

public class Foo
{
    public Foo(IService service = null) {} // optional dependency on IService
}

For @inject and [Inject], there's no such equivalence.

Describe the solution you'd like

I'd love to see a parameter to the Inject attribute that allows to mark a dependency as optional, e.g. [Inject(Optional = true)]. The @inject directive could be extended to make @inject IService Service = null valid and equivalent with [Inject(Optional = true)] IService Service {get;set;} which (as far as I can see) would not break any existing code as it would be a syntax error so far.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions