This chapter shows a few examples that demonstrate how to use Metalama. Each of them is designed as a tutorial, progressively introducing features of growing complexity. You can use these examples to support your learning process.
| Example | Description |
|---|---|
| Validation | Simple aspects relative to validation or normalization of fields, properties, or parameters. |
| Logging | Shows several logging aspects, adding complexity at every step. |
| Caching | Caches the method return value as a function of its parameters. |
| Exception Handling | Demonstrates several exception-handling strategies including retry, Polly, and adding parameter values for richer reports. |
| INotifyPropertyChanged | Implements the INotifyPropertyChanged interface. Shows the ready-made aspect of Metalama.Patterns.Observability for production code, and a custom aspect built step by step for didactic purposes. |
| Change Tracking | Automatically implements the IChangeTracking or IRevertibleChangeTracking interface interface and instruments fields and properties accordingly. |
| Clone | Implements the Deep Clone pattern. |
| Memento | Implements the classic Memento pattern. |
| Enum View-Model | Creates a view-model class to wrap an enum value. |
| Shared Fabric | Demonstrates a fabric that targets several projects. Contributed by Whit Waldo. |
| ToString | Implements the ToString method. |
| Builder | Implements the Builder pattern, i.e. a mutable Builder type nested inside an immutable type. |
| Equatable | Implements the complete equality comparison pattern, including the IEquatable<T> method, and more. |
| Tracing calls | Traces the calls to a library from one file, with interceptors, to investigate a problem without a debugger. |
| Singleton | Generates the boilerplate of the Singleton pattern and enforces it, with or without dependency injection. |
| Auditing and monitoring calls | Audits the calls to sensitive APIs and produces spans and metrics for the calls to an SDK, with interceptors. |
| Interception proxies | Generates an interception proxy for an interface at compile time, without run-time code generation. |
| Metrics | Instruments methods with System.Diagnostics.Metrics counters and generates their dependency injection registration. |
| MAUI Exception Tracking | Tracks exceptions in a .NET MAUI application and records the visual element that caused each one. |
| Getting legacy code under test | Replaces the hard-wired dependencies of legacy code with fakes or recorded interactions, with interceptors, to test the code without changing it. |
| Replacing an implementation | Replaces a component that is called from many places, step by step, by intercepting the calls instead of editing the callers. |
| Universal interceptor | Routes the calls to all the methods of a third-party API to one run-time object, which tests can replace, with interceptors. |
| Authorization | Enforces a role-based authorization model on business objects, configured with hierarchical options. |
If you have developed an original aspect with Metalama, consider contributing to this list.