異なるUnityコンテナーを使用するために、マルチサイト環境の異なるWeb ショップ サイトを構成する方法


解説

例えば、次のような2つのWebショップ サイトを処理するマルチサイト環境があるとします:

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

この場合に、各Webショップ サイトが、異なる「ProductStockManager」を使用するように環境を構成する方法については、以下の解決策をご参照ください。 これは、すべてのSESバージョンに適用できます。

解決策

  1. フォルダーに /Website/App_Config/Sitecore.Ecommerce.Examples.Unity ファイルのコピーを2つ作成します。
    ※註: このファイルは、「Sitecore E-Commerce Services Example Pages」パッケージと共にインストールされます。
  2. acc.ファイルの名前を「{Web ショップの名前}.Unity.config」パターンに変更します:
    - webshop1.Unity.config
    - webshop2.Unity.config
  3. 次の行を追加して、異なる「ProductStockManager」を使用するようにファイルを構成します(「webshop1」サイトの例):
    ...
    <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. /Website/App_Config/Include/Sitecore.Ecommerce.Examples.config ファイル (または /Website/App_Config/Include/Sitecore.Ecommerce.config ファイル) で、次の行を <initialize> パイプラインに追加します:

    <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. Web サイトのアプリケーション プールを再起動します (これは、<initialize> パイプラインを実行するために行います)。

※註: 詳細については、「SES Developer Cookbook」の「Unity Configuration Files」の章を参照してください。