Metalama 1.0 / / Metalama Documentation / Conceptual Documentation / Fabrics


Fabrics are classes that are executed at compile time. Unlike aspects, fabrics do not need to be explicitly added to a declaration. Fabrics are executed just because they exist in the code.

Fabrics are implemented in the Metalama.Framework.Fabrics namespace. See the namespace documentation for a class diagram.


You can use fabrics in the following situations:

  • Add aspects in bulk. Instead of adding aspects to each individual declaration with a custom attribute, you can add them programmatically in bulk. See Adding Aspects in Bulk from a Fabric for details.
  • Validate code. You can add validation rules to your project or namespace using fabrics. See Validating Code with Fabrics for details.
  • Configure an aspect library. When an aspect library exposes a configuration API, you can set the options from a project fabric.

In this chapter

This chapter contains the following articles:

Article Description
Kinds of Fabrics This article describes the different kinds of fabrics and their abilities
Adding Aspects in Bulk from a Fabric This article describes how to use fabrics to programmatically add aspects to several declarations - without custom attributes
Validating Code with Fabrics This article explains how to validate code using fabrics.
Advising the Current Type This article shows how to modify the current type using a type fabric without having to use a separate aspect class.
Configuring Aspects using Project Fabrics This article explains how to use a project fabric to configure an aspect library.
Targeting Multiple Projects with Fabrics This article explains how to target multiple projects with fabrics, either by using a shared fabric in the root directory of your repo, or by using transitive project fabrics.
Execution Order of Fabrics This article explains in which order fabrics and aspects execute in a project.