Marks a field or property in an aspect as a service dependency to be introduced into the target type. This attribute is used in an aspect class to introduce dependencies, whereas DependencyAttribute is used in user code.
Implements
Namespace: Metalama.Extensions.DependencyInjection
Assembly: Metalama.Extensions.DependencyInjection.dll
Syntax
public class IntroduceDependencyAttribute : DeclarativeAdviceAttribute, IAdviceAttributeRemarks
When applied to a field or property within an aspect, this advice will introduce a corresponding dependency into the target type and implement the injection logic according to the configured DI framework. This allows aspects to declare dependencies that will be automatically injected into types where the aspect is applied.
The implementation of dependency injection depends on the selected framework, which can be configured using ConfigureDependencyInjection(IQuery<ICompilation>, Action<DependencyInjectionOptionsBuilder>).
Constructors
| Name | Description |
|---|---|
| IntroduceDependencyAttribute() |
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 |
|---|---|
| BuildAdvice(IMemberOrNamedType, string, IAspectBuilder<IDeclaration>) | Builds the aspect, i.e. translates the current declarative advice into a programmatic advice or possibly diagnostics and validators. In case of error, the implementation must report diagnostics and call SkipAspect(). |
| ToOptions(IFieldOrProperty) |