---
title: "Accessing facets and services"
slug: "accessing-facets-and-services"
abstract: "How to access contact facets, interaction facets, and services such as the xConnect Client API in the context of an interaction aggregation processor."
---
# Accessing facets and services

This topic describes how to access contact facets, interaction facets, and services such as the xConnect Client API in the context of an interaction aggregation processor.

<details>
<summary><h2>Load facets</h2></summary>

The interaction aggregation processing pipeline uses the [xConnect Client API](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/xconnect-client-api-overview.html "xConnect Client API overview") to retrieve contacts and interactions. You must specify which contact and interaction facets to retrieve by decorating your processor with one or both of the following attributes:

- `UsesInteractionFacets`
- `UsesContactFacets`

> [!note]
> Facets are requested from xConnect when the aggregation pipeline is executed. Only request the facet that a processor requires in order to reduce the impact on performance.

In the following example, the processor loads one interaction facet and one contact facet:

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey,Classification.DefaultFacetKey)]
public class UserAgentProcessor:InteractionAggregationPipelineProcessor
{
 protected override void OnProcess(InteractionAggregationPipelineArgsargs)
 {
 }
}
```
> [!important]
> If you do not explicitly request a particular facet, it will not be available during processing. To understand why, read more about the role of expand options when [getting contacts](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/get-contacts.html "Get contacts") and [interactions](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/get-interaction-events.html "Get interaction events").

### Accessing the contact and interaction

The contact and interaction are available on the `args.Context` property:

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey, Classification.DefaultFacetKey)]
public class UserAgentProcessor: InteractionAggregationPipelineProcessor
{
protected override void OnProcess(InteractionAggregationPipelineArgsargs)
  {
  var contact=args.Context.Contact;
  var interaction=args.Context.Interaction;
  }
}
```

If you requested any interaction or contact facets, they can be accessed via the `.GetFacet<T>` extension method:

```csharp
var personalFacet=args.Context.Contact.GetFacet<PersonalInformation>
(PersonalInformation.DefaultFacetKey);

Alternatively, use the extension methods found in `Sitecore.XConnect.Collection.Model`:
```

```csharp
var personalFacet=args.Context.Contact.Personal();
```

</details>

<details>
<summary><h2>Accessing other services</h2></summary>

Every processor has access to the following APIs via `args.Context.Sources`:

- xConnect Client API
- Reference Data Service
- Definition managers
- Taxonomy managers

> [!important]
> In the context of an aggregation processor, all service end points - xConnect, definitions, taxonomy, and the reference data service - are read-only.

### Accessing xConnect

A read-only instance of the xConnect Client API is accessed via `args.Context.Sources.Collection`. You can search or get contact and interaction data:

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey, Classification.DefaultFacetKey)]
public class UserAgentProcessor: InteractionAggregationPipelineProcessor
{
  protected override void OnProcess(InteractionAggregationPipelineArgsargs)
  {
    // Searching
    var contacts = args.Context.Sources.Collection.Contacts.Where(x=>x.Identifiers.Any(c=>c.IdentifierType==ContactIdentifierType.Known));
  var interactions = args.Context.Sources.Collection.Interactions.Where(x=>x.EngagementValue>20);
  // Get some contact or interaction that is not available in the args
  var someID=Guid.NewGuid();
  var contactRef=newList<ContactReference>(){newContactReference(someID)};
  var getContact=args.Context.Sources.Collection.GetAsync<Contact>(contactRef,newContactExpandOptions());
  }
}
```
> [!note]
> Remember that the contact and interaction are available via `args.Context.Contact` and `args.Context.Interaction` respectively.

### Accessing definition managers

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey, Classification.DefaultFacetKey)]
public class UserAgentProcessor:InteractionAggregationPipelineProcessor
{
  protected overridevoidOnProcess(InteractionAggregationPipelineArgsargs)
  {
    protected overridevoidOnProcess(InteractionAggregationPipelineArgsargs)
    {
      var goalManager=
args.Context.Sources.Definitions.GetDefinitionManager<IGoalDefinition>();
    }
  }
}
```
> [!note]
> There is no generic definition manager, which means that you must know which type of event you are looking for and use the appropriate definition manager.

### Accessing taxonomy managers

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey, Classification.DefaultFacetKey)]
public class UserAgentProcessor: InteractionAggregationPipelineProcessor
{
  protected override void OnProcess(InteractionAggregationPipelineArgsargs)
  {
   protected override void OnProcess(InteractionAggregationPipelineArgsargs)
  {
    var assetTaxonomyManager =
args.Context.Sources.Taxonomies.GetManager<AssetTaxonomyManager>();
  }
 }
}
```
> [!note]
> There is no generic taxonomy manager, which means that you must know which type of taxonomy you are looking for and use the appropriate taxonomy manager.

### Accessing the reference data service

```json
[UseInteractionFacets(WebVisit.DefaultFacetKey)]
[UsesContactFacets(PersonalInformation.DefaultFacetKey, Classification.DefaultFacetKey)]
public class UserAgentProcessor: InteractionAggregationPipelineProcessor
{
  protected override void OnProcess(InteractionAggregationPipelineArgsargs)
  {
     var definitionType=args.Context.Sources.Reference.EnsureDefinitionType("alpha");
     var criteria=newDefinitionCriteria("enterprise",definitionType)
     {
        Culture=newCultureInfo("da")
     };
     Definition<string,string>definition=args.Context.Sources.Reference.GetDefinition<string,string>(criteria,true);
  }
}
```
> [!note]
> The aggregation pipeline uses a read only version of the Reference Data Service API that connects directly to the Reference Data Service database.

</details>