Open
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