Using fabrics
Fabrics are special 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 be called from anywhere. Their main method will be called at the right time just because it exists in your code. Therefore, you can think of fabrics as compile-time entry points.
Even if you don't plan to build your own aspects at the moment, learning fabrics will get you to the next level with Metalama.
Using fabrics, you can:
- add aspects programmatically using LINQ-like code queries, instead of tagging individual declarations with custom attributes,
- configure aspect libraries,
- add architecture rules to your code (this is covered in the chapter Validating architecture).
There are four different types of fabrics:
Fabric type | Abstract class | Purposes |
---|---|---|
Project fabrics | ProjectFabric | Add aspects or architecture rules or configure aspect libraries in the current project. |
Transitive project fabrics | ProjectFabric | Add aspects or 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 adding aspects using fabrics. |
Configuring aspects with fabrics | This article explains how to configure aspect libraries using fabrics. |
Adding aspects to many aspects | This article describes how to add aspects to many projects at once. |