// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 using System; using System.Collections.Generic; using System.Text; using Constructs; namespace AWS.Deploy.Recipes.CDK.Common { public delegate void CustomizePropsDelegate(CustomizePropsEventArgs evnt) where GeneratedConstruct : Construct; /// /// Event object created after each CDK constructor properties object is created in the recipe's container construct. /// The CDK properties object can be further customized before the property object is passed into the CDK construct /// making the properties immutable. /// /// public class CustomizePropsEventArgs where GeneratedConstruct : Construct { /// /// The CDK props object about to be used to create the CDK construct /// public object Props { get; } /// /// The CDK logical name of the CDK construct about to be created. /// public string ResourceLogicalName { get; } /// /// The container construct for all of the CDK constructs that are part of the generated CDK project. /// public GeneratedConstruct Construct { get; } public CustomizePropsEventArgs(object props, string resourceLogicalName, GeneratedConstruct construct) { Props = props; ResourceLogicalName = resourceLogicalName; Construct = construct; } } public class CDKRecipeCustomizer where GeneratedConstruct : Construct { /// /// Event called whenever a CDK construct property object is created. Subscribers to the event can customize /// the property object before it is passed into the CDK construct /// making the properties immutable. /// public static event CustomizePropsDelegate? CustomizeCDKProps; /// /// Utility method used in recipes to trigger the CustomizeCDKProps event. /// /// /// /// /// /// public static T InvokeCustomizeCDKPropsEvent(string resourceLogicalName, GeneratedConstruct construct, T props) where T : class { var handler = CustomizeCDKProps; handler?.Invoke(new CustomizePropsEventArgs(props, resourceLogicalName, construct)); return props; } } }