Metalama is an open-source patterns & architecture toolkit for C#.
Define your team's patterns once: the compiler writes the repetitive parts at build time and enforces your rules as you type.
Tip
Using an AI coding assistant or agent? Install Metalama.AI.Skills so it generates correct aspects, fabrics, and architecture rules from the real API instead of inferring it from training data.
- Write the pattern once, apply it everywhere: Aspects generate the repetitive code at compile time; the boilerplate never lands in the repo, so it never needs review or maintenance.
- Enforce architecture as you type: Dependency rules, naming conventions, and pattern guidelines in plain C#, with real-time IDE feedback long before the pull request.
- Stay consistent in the AI era: Hand-written or AI-generated, every line is checked against your rules; a pattern change is one file edit and the whole codebase follows at the next build.
Built on Roslyn by the PostSharp team, who have been doing compiler-level meta-programming in .NET since 2004.
Metalama is ideal for:
- Large projects: Automate repetitive patterns across dozens of entities and hundreds of properties or methods.
- Large teams: Align developers on consistent patterns and practices.
- Long lifecycle projects: Maintain quality over years of development.
Its main use cases are:
- Design Patterns: Singleton, Memento, Factory, Builder, Decorator, Proxy, ...
- UI Patterns: INotifyPropertyChanged, Change Tracking, Memoization, Undo/Redo, Command, Dependency Properties, Enum View-Model ...
- Object Services: Cloning, ToString, Comparison, ...
- Defensive Programming: Code Contracts (preconditions, post-conditions, invariants)
- DevOps: Logging & Tracing, Metrics, Caching, Exception Handling
- Architecture Validation 💎
- Refactoring
- In general, Clean Code and SOLID & DRY Principles
Metalama is vendor-led open source: built and maintained by full-time engineers, funded by commercial licenses.
The core framework, which is the large majority of the codebase, is released under the MIT license. It cannot be taken away, relicensed, or paywalled.
Some optional extensions and IDE tooling are released under a proprietary license and are marked with a diamond 💎 symbol.
- Code Generation
- Code Validation
- Immediate Editor Feedback
- Code Fix Toolkit 💎
- Ready-to-Use Aspect Libraries
- Visual Studio Tooling 💎
- Test Frameworks
- Debugging of Transformed Code
- Roslyn Extensibility SDK
- Code Query API
- Metalama Website
- Documentation
- Annotated Examples
- Changelogs
- Release Notes
- Metalama Tools for Visual Studio Extension
-
Add the
Metalama.Frameworkpackage to your project:dotnet add package Metalama.Framework
-
Optionally, install Metalama Tools for Visual Studio Extension. It's free for individuals, non-commercial uses, and companies with up to 3 users.
-
Explore the Metalama Marketplace for ready-made aspects or examples.
-
Follow the Getting Started guide to create your first aspect.
Contributions are accepted through the following channels:
- Share your aspects on the Metalama Marketplace.
- Contribute aspects to Metalama.Community.
- Improve the documentation. Learn how.
- Fix bugs or contribute code. Learn how.
For more details, see Contributing to Metalama.
- Report issues on GitHub. Follow these recommendations.
- Ask questions and submit proposals in GitHub discussions.
- Enterprise support is available. Learn more about premium support. 💎
Here are the principal repositories that make Metalama:
| Repository | License | Description |
|---|---|---|
| Metalama | MIT | Our main repository containing the full open-source product. |
| Metalama.Compiler | MIT | Our fork of Roslyn adding an extensibility API for source code transformations. |
| PostSharp.Engineering | MIT | A custom multi-repo build and CI framework. |
| Metalama.Community | MIT | Community-contributed aspects repository. |
| Metalama.Documentation | MIT | Source for documentation hosted on Metalama Docs. |
| Metalama.Samples | MIT | Illustrative samples available at Metalama Examples. |
| Metalama.Premium 💎 | Proprietary | Extensions available to customers with a commercial license. |
Below is a list of packages produced from this organization:
| Package Name | License | Description |
|---|---|---|
| Metalama.Framework | MIT | This is Metalama's main and core package. It incorporates a reference to Metalama.Compiler, effectively replacing the Roslyn compiler with our custom version. |
| Metalama.Framework.Redist | MIT | Contains the public API of the Metalama Framework, without Metalama.Compiler. Reference this package to produce your own packages when you don't want them to use the forked compiler. |
| Metalama.Compiler | MIT | A fork of Roslyn that allows add-ins (such as Metalama.Framework) to perform arbitrary code transformations. |
| Metalama.Testing.UnitTesting | MIT | Provides base classes and utilities for unit testing compile-time code. |
| Metalama.Testing.AspectTesting | MIT | A framework based on xUnit for testing code generation by aspects. |
| Metalama.Framework.Sdk | MIT | Facilitates the use of the Roslyn API from aspects. |
| Metalama.Framework.Engine | MIT | This is the core implementation of Metalama.Framework. Direct referencing of this package is discouraged and unsupported. It's intended to be a dependency for Metalama.Testing.AspectTesting. |
| Metalama.Framework.CompileTimeContracts | MIT | Defines the public API between compiled T# templates and Metalama.Framework.Engine. |
| Metalama.Framework.Introspection | MIT | Provides an API to inspect the object model that represents the compilation process of Metalama.Framework, such as aspect and advice instances, as well as its results. |
| Metalama.Framework.Workspaces | MIT | A supplementary API to Metalama.Framework.Introspection, designed to facilitate the loading of Visual Studio projects and solutions. This package is also useful to inspect projects that don't use Metalama. It is used by Metalama.LinqPad. |
| Metalama.Tool | MIT | The metalama tool for the .NET CLI. |
| Metalama.Extensions.DependencyInjection | MIT | A framework that allows aspects to consume dependencies from an arbitrary dependency injection framework. |
| Metalama.Extensions.Metrics | MIT | Implements code metrics that can be consumed by aspects and fabrics. |
| Metalama.Extensions.Multicast | MIT | Reproduces PostSharp attribute multicasting in Metalama, for teams porting business code from one to the other. |
| Metalama.Patterns.Caching | MIT | Comprehensive caching framework for Metalama. |
| Metalama.Patterns.Caching.Aspects | MIT | Aspects designed for Metalama caching, building upon Metalama.Patterns.Caching. |
| Metalama.Patterns.Caching.Backend | MIT | Provides an abstraction over caching backends, including an in-memory caching implementation. |
| Metalama.Patterns.Contracts | MIT | Code contract aspects like [NotNull], [Url] for contract-based programming. |
| Metalama.Patterns.Immutability | MIT | Represents the concept of Immutable Type so that it can be used by other packages like Metalama.Patterns.Observability. |
| Metalama.Patterns.Memoization | MIT | Implements a memoization aspect, i.e. simple, low-overhead caching. |
| Metalama.Patterns.Observability | MIT | A Metalama aspect implementing INotifyPropertyChanged. |
| Metalama.Patterns.Wpf | MIT | Aspects that implement WPF dependency properties and commands. |
| Metalama.LinqPad | MIT | Provides integration with LINQPad for inspecting projects and solutions. |
| Flashtrace | MIT | A structured tracing library used by Metalama.Patterns.Caching. |
| Flashtrace.Formatters | MIT | Object formatters used in caching and logging. |
| Metalama.Licensing 💎 | Proprietary | This package verifies that the user or the project has a valid license for Metalama. |
| Metalama.Extensions.CodeFixes 💎 | Proprietary | Enables aspects and fabrics to suggest custom code fixes. |
| Metalama.Extensions.Validation 💎 | Proprietary | Provides a base API for aspects and fabrics to validate source code, including the validation of code references and dependencies. |
| Metalama.Extensions.Architecture 💎 | Proprietary | Extends the Metalama.Extensions.Validation package with a high-level API to validate source code against architecture rules. |
| Metalama.Patterns.Caching.Backends.Redis 💎 | Proprietary | Implements a Metalama.Patterns.Caching adapter for Redis, allowing for distributed caching and hybrid caching. |
| Metalama.Patterns.Caching.Backends.Azure 💎 | Proprietary | Implements cache synchronization for Metalama.Patterns.Caching using Azure Service Bus, allowing several local caches to stay synchronized in a multi-node deployment. |