MetalamaConceptual documentationUsing MetalamaMore about fabrics
Open sandboxFocusImprove this doc

Fabrics

In the previous article, we discussed how to add multiple aspects at once using compile-time imperative code, as opposed to declarative custom attributes. We introduced a single type of fabric: ProjectFabric. However, there are several other types of fabrics and numerous use cases for them.

Even if you currently have no plans to create your own aspects, understanding fabrics will enhance your proficiency with Metalama.

Fabrics are unique classes in your code that execute at compile time within the compiler and at design time within your IDE. Unlike aspects, fabrics do not need to be applied to any declaration or called from anywhere. Their primary method will be invoked at the appropriate time simply because it exists in your code. Therefore, you can think of fabrics as compile-time entry points.

With fabrics, you can:

In addition to ProjectFabric, there are three more types of fabric:

Fabric Type Abstract Class Purpose
Project Fabrics ProjectFabric Add aspects, architecture rules, or configure aspect libraries in the current project.
Transitive Project Fabrics TransitiveProjectFabric Add aspects, architecture rules, or configure aspect libraries in projects that reference the current project.
Namespace Fabric NamespaceFabric Add aspects or architecture rules to the namespace that contains the fabric type.
Type Fabric TypeFabric Add aspects to different members of the type that contains the nested fabric type.

Let's now explore the second use case of fabrics: configuration.