---
title: "カスタムCommerceパイプラインまたはブロックの登録"
slug: "registering-a-custom-commerce-pipeline-or-block"
abstract: "カスタムCommerceプラグインのConfigureSitecoreクラスを使ってビジネスロジックを定義するためのガイダンスです。"
---
# カスタムCommerceパイプラインまたはブロックの登録

Microsoft Visual Studioでカスタムプラグインプロジェクトを作成する際、Sitecore.Commerce.Plugin.Sampleプロジェクトテンプレート( Sitecore.Commerce.Engine.SDK(sitecore-commerce-engine-sdk.md "Sitecore Commerce Engine SDK")の一部として提供)には必要なConfigureSitecoreクラスが含まれています。 ConfigureSitecoreクラスは通常、プラグインプロジェクトのルートに配置されます。

必要なビジネスロジックを実装するには、カスタムパイプラインとブロックをConfigureServicesメソッド( ConfigureSitecoreクラスの一部)に追加し、他のパイプラインブロックとの依存関係を定義します。 ConfigureSitecoreクラスでは、新しいパイプラインやカスタムブロックをCommerce Engineに登録し、ブロックの実行順序を設定できます。

他のCommerceパイプラインブロックへの依存関係を特定し定義するために、実行中のCommerce Engineインスタンスの [現在登録済みパイプラインのログを見る](https://doc.sitecore.com/xp/ja/developers/101/sitecore-experience-commerce/view-running-pipelines.html "View running pipelines") か、Postmanを使って [登録済みパイプラインを取得する](https://doc.sitecore.com/xp/ja/developers/101/sitecore-experience-commerce/retrieve-registered-pipelines.html "Retrieve registered pipelines")ことができます。

カスタムプラグインが依存する既存のパイプラインとブロックを特定したら、.addpipelineメソッドを使って必要なパイプラインをConfigureServicesメソッドに追加します。各パイプラインは、提供されるパイプラインブロックに対して実行する関数を指定することで設定します。

パイプラインフレームワークは以下のメソッドと関数をサポートしています:

-   .configure.Replace - この方法を使って既存のパイプラインブロックを新しいブロックに置き換える。例えば:
    
    services.Sitecore().Pipelines(config => config
                 .ConfigurePipeline<IFormatEntityViewPipeline>(
                        configure =>
                        {
                            configure.Replace<GetEntityViewBlock>, <NewGetEntityViewBlock>();
                        })
          );
    
-   .configure.Remove - 既存のパイプラインから不要な機能ブロックを除去するためにこのメソッドを使用する。例えば:
    
    services.Sitecore().Pipelines(config => config
                 .ConfigurePipeline<IFormatEntityViewPipeline>(
                        configure =>
                        {
                            configure.Remove<CalculateCartLinesFulfillmentBlock>();
                        })
          );
    

以下の例は、カスタムブロック(.Add<AddOrderToServiceBusSendListBlock>)を挿入するように設定されたパイプラインを示しており、その定義されたアクションがIPersistOrderPipelineの実行*前に*行われるようにしています:

.ConfigurePipeline<ICreateOrderPipeline>(configuration => configuration
 .Add<AddOrderToServiceBusSendListBlock>().Before<IPersistOrderPipeline>()
 )

以下の例では、パイプライン構成が<PopulateEntityViewActionsBlock>の*実行後に*カスタムブロック.Add<EnsureActions>挿入します。

.ConfigurePipeline<IFormatEntityViewPipeline>(configuration => configuration
 .Add<EnsureActions>().After<PopulateEntityViewActionsBlock>()
 .Add<EnsurePluginActions>().After<PopulateEntityViewActionsBlock>()

## サンプルConfigureSitecoreクラス

以下は、Sitecore.Commerce.Plugin.SampleプロジェクトテンプレートがデフォルトでVisual Studioで作成するサンプルConfigureSitecoreクラスの例を示しています。

namespace Sitecore.Commerce.Plugin.Sample
{
 using System.Reflection;
 using Microsoft.Extensions.DependencyInjection;
 using Sitecore.Commerce.Core;
 using Sitecore.Framework.Configuration;
 using Sitecore.Framework.Pipelines.Definitions.Extensions;

 /// <summary>
 /// The configure sitecore class.
 /// </summary>
 public class ConfigureSitecore : IConfigureSitecore
 {
 /// <summary>
 /// The configure services.
 /// </summary>
 /// <param name="services">
 /// The services.
 /// </param>
 public void ConfigureServices(IServiceCollection services)
 {
 var assembly = Assembly.GetExecutingAssembly();
 services.RegisterAllPipelineBlocks(assembly);

 services.Sitecore().Pipelines(config => config

 .AddPipeline<ISamplePipeline, SamplePipeline>(
 configure =>
 {
 configure.Add<SampleBlock>();
 })

 .ConfigurePipeline<IConfigureServiceApiPipeline>(configure => configure.Add<ConfigureServiceApiBlock>()));

 services.RegisterAllCommands(assembly);
 }
 }
}