---
title: "getContactパイプラインの拡張"
slug: "extending-the-getcontact-pipeline"
abstract: "プレビューモードで使用できるカスタムパーソナライズトークンを作成するためのコードサンプル。"
---
# getContactパイプラインの拡張

オンラインプレビューモードで[カスタムパーソナライズトークン](https://doc.sitecore.com/xp/ja/developers/exm/100/email-experience-manager/create-a-custom-personalization-token.html "Create a custom personalization token") を置き換えたい場合は、getContactパイプラインを拡張してください。

> !注このトピックはSitecoreのバージョン9.0.1以降に適用されます。

getContactパイプラインを拡張するには:

1.  新しいパイプラインプロセッサを作成します。以下の例を参照してください。
2.  パイプラインプロセッサでアセンブリをすべてのCMおよびDDSインスタンスにデプロイしてください。
3.  \\App\_Config\\Sitecore\\EmailExperienceディレクトリに移動してください。
4.  [設定パッチファイルを作成し](https://doc.sitecore.com/xp/en/developers/100/platform-administration-and-architecture/use-a-patch-file-to-customize-the-sitecore-configuration.html)、SitecoreのgetContactパイプラインのSitecore.Modules.EmailCampaign.Core.Pipelines.GetContact.GetContactプロセッサを置き換えます。EmailExperience.Core.configファイル。

以下の例は、getContactパイプラインの拡張方法を示しています。

using System;
using System.Linq;
using Sitecore;
using Sitecore.Data;
using Sitecore.Framework.Conditions;
using Sitecore.Modules.EmailCampaign.Core.Contacts;
using Sitecore.Modules.EmailCampaign.Core.Pipelines.GetContact;

namespace MyNamespace
{
 public class GetContact
 {
 private readonly IContactService \_contactService;

 public GetContact(NotNull IContactService contactService)
 {
 Condition.Requires(contactService, nameof(contactService)).IsNotNull();

 \_contactService = contactService;
 }

 public void Process(NotNull GetContactPipelineArgs args)
 {
 Condition.Requires(args, nameof(args)).IsNotNull();

 if (args.ContactIdentifier == null && ID.IsNullOrEmpty(args.ContactId))
 {
 throw new ArgumentException("Either the contact identifier or the contact id must be set");
 }

 string facetKeys = args.FacetKeys.Concat(new
 {
 "CustomFacetName" // the custom facet name
 }).ToArray();

 args.Contact =
 args.ContactIdentifier != null ?
 \_contactService.GetContact(args.ContactIdentifier, facetKeys)
 :
 \_contactService.GetContact(args.ContactId, facetKeys);
 }
 }
}