Open sandboxFocus

Class DependencyAttribute

Marks a field or automatic property as a service dependency that should be injected by the dependency injection framework. This attribute is used in user code, whereas IntroduceDependencyAttribute is used in aspect code to introduce dependencies.

Inheritance
DependencyAttribute
Namespace: Metalama.Extensions.DependencyInjection
Assembly: Metalama.Extensions.DependencyInjection.dll
Syntax
public class DependencyAttribute : FieldOrPropertyAspect, IAspect<IFieldOrProperty>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IFieldOrProperty>
Remarks

When applied to a field or property, this aspect will automatically implement dependency injection according to the configured DI framework (e.g., constructor injection, property injection). The implementation depends on the selected dependency injection framework, which can be configured using ConfigureDependencyInjection(IQuery<ICompilation>, Action<DependencyInjectionOptionsBuilder>).

Constructors

Name Description
DependencyAttribute()

Properties

Name Description
IsLazy

Gets or sets a value indicating whether the dependency should be pulled from the container lazily, i.e. upon first use.

IsRequired

Gets or sets a value indicating whether the dependency is required.

Methods

Name Description
BuildAspect(IAspectBuilder<IFieldOrProperty>)

Defines the aspect implementation by adding advice, child aspects, and validators to the target declaration.

ToProperties(IFieldOrProperty)

Extension Methods

See Also