Skip to content

Comments

feat(mixin): add IMixin interface and Construct.with() method#2843

Merged
mrgrain merged 1 commit into10.xfrom
mrgrain/feat/mixins
Feb 17, 2026
Merged

feat(mixin): add IMixin interface and Construct.with() method#2843
mrgrain merged 1 commit into10.xfrom
mrgrain/feat/mixins

Conversation

@mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Feb 2, 2026

This PR implements the constructs package parts of RFC-0814: CDK Mixins.

CDK Mixins are composable, reusable abstractions that can be applied to any construct. This change adds the foundational support to the constructs library, enabling the fluent .with() API described in the RFC.

Changes

The IMixin interface defines the contract for mixins with two methods:

  • supports(construct) - determines if a mixin can be applied to a given construct
  • applyTo(construct) - applies the mixin functionality to the target

The with() method is added to Construct and IConstruct, allowing mixins to be applied fluently. When called, it traverses the construct tree and applies each mixin to all supported constructs.

const bucket = new s3.CfnBucket(scope, "MyBucket")
  .with(new EncryptionAtRest())
  .with(new AutoDeleteObjects());

Why

Mixins are a new way to build abstractions, that does not rely on the construct level approach many implementors use. They allow users to employ a mix and match approach for features that doesn't lock consumers into specific implementations.

@mrgrain mrgrain marked this pull request as draft February 2, 2026 13:25
auto-merge was automatically disabled February 2, 2026 13:25

Pull request was converted to draft

Implements the constructs package parts of RFC-0814 (CDK Mixins).

Adds the `IMixin` interface with `supports()` and `applyTo()` methods,
and the `with()` method on `Construct` and `IConstruct` for fluent
mixin application across construct trees.
@mrgrain mrgrain force-pushed the mrgrain/feat/mixins branch from 6e13154 to 87dcc0b Compare February 2, 2026 13:40
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Feb 3, 2026
### Issue # (if applicable)

Related RFC: aws/aws-cdk-rfcs#824

### Reason for this change

Aligns the implementation with the latest version of the [Mixins RFC](aws/aws-cdk-rfcs#824).

The `.with()` method previously iterated over constructs first, then mixins. This meant that mixins were not guaranteed to be applied in the order they were passed to the method. Additionally, if a mixin added new constructs to the tree, subsequent mixins in the same call could unexpectedly visit those newly added constructs.

### Description of changes

Changed the loop order so that mixins are applied in order. The list of constructs is now captured at the start of the call, ensuring that constructs added by a mixin will not be visited by subsequent mixins. Users who need subsequent mixins to apply to added constructs can use multiple `.with()` calls.

Also improved variable naming for clarity (`c` → `construct`, `m` → `mixin`).

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Existing tests pass. This behavior is explicitly tested in aws/constructs#2843.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
aemada-aws pushed a commit to aemada-aws/aws-cdk that referenced this pull request Feb 11, 2026
### Issue # (if applicable)

Related RFC: aws/aws-cdk-rfcs#824

### Reason for this change

Aligns the implementation with the latest version of the [Mixins RFC](aws/aws-cdk-rfcs#824).

The `.with()` method previously iterated over constructs first, then mixins. This meant that mixins were not guaranteed to be applied in the order they were passed to the method. Additionally, if a mixin added new constructs to the tree, subsequent mixins in the same call could unexpectedly visit those newly added constructs.

### Description of changes

Changed the loop order so that mixins are applied in order. The list of constructs is now captured at the start of the call, ensuring that constructs added by a mixin will not be visited by subsequent mixins. Users who need subsequent mixins to apply to added constructs can use multiple `.with()` calls.

Also improved variable naming for clarity (`c` → `construct`, `m` → `mixin`).

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Existing tests pass. This behavior is explicitly tested in aws/constructs#2843.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mrgrain mrgrain marked this pull request as ready for review February 17, 2026 09:43
@mrgrain mrgrain added this pull request to the merge queue Feb 17, 2026
@mrgrain mrgrain removed this pull request from the merge queue due to a manual request Feb 17, 2026
@mrgrain mrgrain added this pull request to the merge queue Feb 17, 2026
Merged via the queue into 10.x with commit 0f1005b Feb 17, 2026
14 of 15 checks passed
@mrgrain mrgrain deleted the mrgrain/feat/mixins branch February 17, 2026 09:46
github-merge-queue bot pushed a commit to projen/projen that referenced this pull request Feb 20, 2026
The default version of the `constructs` library for CDK 2.x projects has
been stuck at `10.0.5` since CDK 2 was first introduced.

Bumping the default to `10.5.1` enables support for CDK Mixins out of
the box. Constructs `10.5.0` introduced the `IMixin` interface and
`Construct.with()` method (aws/constructs#2843), allowing newly created
projects to use this feature without manually upgrading their constructs
dependency.

Additionally, the default for `cdkVersion` is updated to `2.189.1`,
which is the oldest CDK version without a published security advisory.
This makes it a suitable minimum version for CDK Construct Libraries.
Only affects new projects, which will now be created by putting this
version into the generated projen RC file.

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit to projen/projen that referenced this pull request Feb 20, 2026
The default version of the `constructs` library for CDK 2.x projects has
been stuck at `10.0.5` since CDK 2 was first introduced.

Bumping the default to `10.5.1` enables support for CDK Mixins out of
the box. Constructs `10.5.0` introduced the `IMixin` interface and
`Construct.with()` method (aws/constructs#2843), allowing newly created
projects to use this feature without manually upgrading their constructs
dependency.

Additionally, the default for `cdkVersion` is updated to `2.189.1`,
which is the oldest CDK version without a published security advisory.
This makes it a suitable minimum version for CDK Construct Libraries.
Only affects new projects, which will now be created by putting this
version into the generated projen RC file.

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants