# Umbraco Commerce Builder

When it comes to configuring and extending Umbraco Commerce, such as by registering your own event handlers, we achieve this with the `IUmbracoCommerceBuilder` interface that can be accessed via a delegate function passed into the `AddUmbracoCommerce()` extension method called on the `IUmbracoBuilder` interface when explicitly registering Umbraco Commerce.

```csharp
builder.CreateUmbracoBuilder()
    .AddBackOffice()
    .AddWebsite()
    .AddUmbracoCommerce(umbracoCommerceBuilder => {
    // Configure Umbraco Commerce here
    })
    .AddDeliveryApi()
    .AddComposers()
    .Build();

```

## Registering Dependencies

The `IUmbracoCommerceBuilder` interface gives you access to the current `IServiceCollection` and `IConfiguration` to allow you to register dependencies like you would with the [`IUmbracoBuilder` interface](https://docs.umbraco.com/umbraco-commerce/dependency-injection#registering-dependencies) but its primary use case would be to access Umbraco Commerce's own collection builders, such as for registering validation or notification events, and any other Umbraco Commerce-specific configuration APIs.

```csharp
...
.AddUmbracoCommerce(umbracoCommerceBuilder => {

    // Register validation events
    umbracoCommerceBuilder.WithValidationEvent<ValidateOrderProductAdd>()
            .RegisterHandler<MyOrderProductAddValidationHandler>();

})
...
```

As per the [Dependency Injection docs](https://docs.umbraco.com/umbraco-commerce/key-concepts/dependency-injection), whilst you can register your dependencies directly within this configuration delegate, you may prefer to group your dependencies registration code into an extension method.

```csharp
public static class UmbracoCommerceUmbracoBuilderExtensions
{
    public static IUmbracoCommerceBuilder AddMyDependencies(this IUmbracoCommerceBuilder builder)
    {
        // Register my dependencies here via the builder parameter
        ...

        // Return the builder to continue the chain
        return builder;
    }
}
```

```csharp
...
.AddUmbracoCommerce(umbracoCommerceBuilder => {

    umbracoCommerceBuilder.AddMyDependencies();

})
...
```

{% hint style="info" %}
If using a composer to register `IUmbracoCommerceBuilder` extensions and their dependencies, the composer needs to run before `UmbracoCommerceComposer` otherwise it will use the default configuration.
{% endhint %}

```csharp
public static class StoreBuilderExtensions
{
	public static IUmbracoBuilder AddMyStore(this IUmbracoBuilder umbracoBuilder)
	{
		umbracoBuilder.AddUmbracoCommerce(v =>
		{
			...
		});

		return umbracoBuilder;
	}
}
```

```csharp
[ComposeBefore(typeof(UmbracoCommerceComposer))]
public class StoreComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.AddMyStore();
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.umbraco.com/umbraco-commerce/key-concepts/umbraco-commerce-builder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
