---
title: "Deploy a custom model"
slug: "deploy-a-custom-model"
abstract: "How to serialize and deploy a custom model to xConnect."
---
# Deploy a custom model

This topic describes how to serialize and deploy custom model to xConnect. Model deployment is a manual process that involves copying a JSON representation of a model to all instances of xConnect.

<details>
<summary><h2>Serialize the model to JSON</h2></summary>

To serialize the model to JSON:

1. Create a console application to serialize the xConnect model.
2. Serialize the model to JSON as shown - the following example uses Sitecore’s default collection model.

    ```csharp
    using Sitecore.XConnect.Serialization;

    namespace Documentation
    {
        public class DeployModel
        {
            public void Serialize()
            {
                // File name will be Sitecore.XConnect.Collection.Model, 9.0.json
                var json = XdbModelWriter.Serialize(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            }
        }
    }
    ```
    > [!important]
    > Do not change the file name. The file name must match the name declared in the model class.

</details>

<details>
<summary><h2>Deploy the model to xConnect and Marketing Automation Operations</h2></summary>

To deploy the custom model to the xConnect and Marketing Automation Operations roles:

1. Copy the model JSON file to the following path on all instances of xConnect Collection Search and xConnect Collection roles:

    `C:\<Path to xConnect>\root\App_Data\Models`

2. Copy the model JSON file to the following path on in the xConnect Search Indexer.

    `C:\<Path to indexer>\root\App_data\Models`

    > [!note]
    > By default, the xConnect Search Indexer is located under `C:\<Path to xConnect>\App_data\jobs\continuous\IndexWorker`.

3. In Sitecore 9.0 Update 2 and later, you must copy the model JSON file to the following path on all instances of the Marketing Automation Operations role. The model is required in order to process live events:

    `C:\<Path to marketing automation operations>\root\App_Data\Models`

    > [!note]
    > Step 3 is not necessary if your Marketing Automation Operations role is combined with xConnect Collection Search or xConnect Collection.

</details>

<details>
<summary><h2>Deploy the model to the Marketing Automation Engine</h2></summary>

Complete the following steps in order to work with custom model data in the context of custom activity types. This functionality is available in 9.0 Update-1 onwards.

To deploy the model to the Marketing Automation Engine:

1. Copy the model DLL to the root of every instance of the Marketing Automation Engine.

    > [!note]
    > The Marketing Automation Engine does not need a JSON representation of the model. By default, the Marketing Automation Engine is located under `C:\<Path to xConnect>\App_data\jobs\continuous\AutomationEngine`.

2. In `C:\<Path to xConnect>\App_data\jobs\continuous\AutomationEngine\AppData\config\sitecore`, create a configuration file named `sc.Sample.CustomModel.xml`. The file name must start with `sc` and end with `.xml`. Paste the following model configuration and make the following changes:
    - Change the `TypeName` to the fully qualified name of your model.
    - Optionally, rename the `CustomModel1` node.

    ```xml
    <Settings>
        <Sitecore>
            <XConnect>
                <Services>
                    <XConnect.Client.Configuration>
                        <Options>
                            <Models>
                                <CustomModel1>
                                    <TypeName>Sitecore.Xdb.MarketingAutomation.Stub.Model.StubModel, Sitecore.Xdb.MarketingAutomation.Stub</TypeName>
                                </CustomModel1>
                            </Models>
                        </Options>
                    </XConnect.Client.Configuration>
                </Services>
            </XConnect>
        </Sitecore>
    </Settings>
    ```

It is assumed your model exposes a static property named `Model` which returns the `XdbModel` for your model. If your custom model exposes the model from a different static property, include the name of the property in a `PropertyName` element inside the `CustomModel` element:

```xml
<Settings>
    <Sitecore>
        <XConnect>
            <Services>
                <XConnect.Client.Configuration>
                    <Options>
                        <Models>
                            <CustomModel1>
                                <TypeName>Sitecore.Xdb.MarketingAutomation.Stub.Model.StubModel, Sitecore.Xdb.MarketingAutomation.Stub</TypeName>
                                                                    <PropertyName>TheModel</PropertyName>
                            </CustomModel1>
                        </Models>
                    </Options>
                </XConnect.Client.Configuration>
            </Services>
        </XConnect>
    </Sitecore>
</Settings>
```

</details>

<details>
<summary><h2>Deploy the model to core roles</h2></summary>

Finally, you must deploy your custom model to all core Sitecore instances. This includes the following roles:

- Content Delivery
- Content Management
- xDB Processing

On each core Sitecore instance:

1. Copy the model DLL into the bin directory of your core Sitecore instance.
2. Patch your own model class into `\App_Config\Sitecore\XConnect.Client.Configuration\Sitecore.XConnect.Client.config` as shown:

    ```xml
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <xconnect>
        <runtime type="Sitecore.XConnect.Client.Configuration.RuntimeModelConfiguration,Sitecore.XConnect.Client.Configuration">
            <schemas hint="list:AddModelConfiguration">
                <!-- value of 'name' property must be unique -->
                <schema name="documentationmodel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration" patch:after="schema[@name='collectionmodel']">
                    <param desc="modeltype">Documentation.Model.CollectionModel, Documentation.Model</param>
                </schema>
            </schemas>
        </runtime>
        </xconnect>
    </sitecore>
    </configuration>
    ```

3. In your code, reference the model DLL.
4. Use the xConnect Client API to [trigger your event](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/add-interaction-events.html "Add interaction events") or [populate your contact facet](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/set-contact-facets.html "Set contact facets").

> [!note]
> You can also [use the model outside of a Sitecore context](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/instantiate-client-in-a-non-sitecore-context.html "Instantiate client in a non-Sitecore context").

</details>