IComponentInitializer

This interface allows you do define initializers which can populate the properties of components when they are added onto a page.  This can be used to apply default values to properties, either hard-coded or dynamic depending on where the component is being added.

Interface declaration

	public interface IComponentInitializer
	{
		Task Initialize(Guid componentId, Dictionary<string, object> propertyValues, ComponentInitializationContext context);
	}

Example

In this example, we are targeting the Link component explicitly, by checking the ID of the component which is being added.  We then apply default values to it's Class property.

	public class DefaultClassForLinkComponentInitializer : IComponentInitializer
	{
		public async Task Initialize(Guid componentId, Dictionary<string, object> propertyValues, ComponentInitializationContext context)
		{
			if (componentId == new Guid("AA2EF9B4-ED7F-4456-98BF-836DDB7D9BA4"))
			{
				propertyValues.AddOrUpdate("Class", "btn btn-primary");
			}
		}
	}

Registration

This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).

		public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
		{
			services.AddNamed<IComponentInitializer, DefaultClassForLinkComponentInitializer>(ServiceLifetime.Transient);
		}

Once it has been registered into the DI container, this initializer will be executed when components are added to pages/templates in Veva and if the componentId matches (in this case the Link component), we add a default value of "btn btn-primary" to it's Class property.