How to configure different webshop sites of multisite environment to use different Unity containers?


Description

For example, for a multisite environment that handle two webshop sites:

<sites>
  <site name=”webshop1” ……. />
  <site name=”webshop2” ……. />
  ...
</sites>

See the Solution below to configure the environment so each of the webshop sites uses a different “ProductStockManager”. This applies to all SES versions.

Solution

  1. Make two copies of the /Website/App_Config/Sitecore.Ecommerce.Examples.Unity file in the folder.
    Note: the file is installed with the "Sitecore E-Commerce Services Example Pages" package.
  2. Rename the files acc. to the "{name of your webshop}.Unity.config" pattern:
    - webshop1.Unity.config
    - webshop2.Unity.config
  3. Configure the files to use different "ProductStockManager" by adding there the following lines (example for "webshop1" site):

    ...
    <alias alias="ProductStockManager" type="{custom namespace}.ProductStockManagerWebShop1, {custom assembly name}" />
     
    <alias alias="IProductStockManager" type="Sitecore.Ecommerce.DomainModel.Products.IProductStockManager, Sitecore.Ecommerce.DomainModel" />
    <container>
    ...
    <register type="IProductStockManager" mapTo="ProductStockManager">
    <lifetime type="hierarchical" />
    </register>
    ...
    </container>
  4. In the /Website/App_Config/Include/Sitecore.Ecommerce.Examples.config file (or /Website/App_Config/Include/Sitecore.Ecommerce.config file) add the following lines to the <initialize> pipeline:

    <pipelines>
      <initialize>
        ...
        <processor type="Sitecore.Ecommerce.Pipelines.Loader.ConfigureEntities, Sitecore.Ecommerce.Kernel" patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']" name="examplesunityconfiginitializer">
          <UnityConfigSource>/App_Config/webshop1.Unity.config</UnityConfigSource>
        </processor> 
        <processor type="Sitecore.Ecommerce.Pipelines.Loader.ConfigureEntities, Sitecore.Ecommerce.Kernel" patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']" name="examplesunityconfiginitializer">
          <UnityConfigSource>/App_Config/webshop2.Unity.config</UnityConfigSource>
        </processor> 
        ...
       </initialize>
       ...
    </pipelines>
  5. Restart the application pool of the website (in order to run the <initialize> pipeline). 

Notes: for more details please see the "Unity Configuration Files" chapter of the "SES Developer Cookbook".