Using Fabrics
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 require 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. Hence, you can perceive fabrics as compile-time entry points.
Even if you presently have no plans to construct your own aspects, understanding fabrics will elevate your proficiency with Metalama.
With fabrics, you can:
- Add aspects programmatically using LINQ-like code queries, instead of marking individual declarations with custom attributes.
- Configure aspect libraries.
- Implement architecture rules to your code (this topic is discussed in the chapter Verifying architecture).
There are four distinct types of fabrics:
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. |
In This Chapter
Article | Description |
---|---|
Adding many aspects at once | This article describes how to add aspects using fabrics. |
Configuring aspects with fabrics | This article explains how to configure aspect libraries using fabrics. |
Adding aspects to many projects | This article describes how to add aspects to multiple projects simultaneously. |