Class OptionsAttribute

Controls the IInjector during the dependency resolution.

Inheritance
System.Object
OptionsAttribute
Namespace: Solti.Utils.DI.Interfaces
Assembly: Solti.Utils.DI.Interfaces.dll
Syntax
public sealed class OptionsAttribute : Attribute
Remarks

Constructors

OptionsAttribute()

Declaration
public OptionsAttribute()

Properties

Key

The (optional) service key. The value of this property will be passed to the corresponding scope invocation:

class MyService
{
    public MyService([Options(Key = "...")] IDependency dependency) {...}
}

translates to

scope => new MyService(scope.Get(typeof(IDependency), options.Key))
Declaration
public object Key { get; set; }
Property Value
Type Description
System.Object

Optional

Indicates whether a dependency is optional or not. In practice:

class MyService
{
    public MyService([Options(Optional = true)] IDependency dependency) {...}
}

translates to

scope => new MyService(scope.TryGet(typeof(IDependency), options.Key))

while

class MyService
{
    public MyService([Options(Optional = false)] IDependency dependency) {...}
}

becomes

scope => new MyService(scope.Get(typeof(IDependency), options.Key))
Declaration
public bool Optional { get; set; }
Property Value
Type Description
System.Boolean
Remarks

This option is ignored if you are using the MS preferred DI (System.IServiceProvider).

In This Article
Back to top Generated by DocFX