Skip to content
Shiny.Maui.Shell v6 support for AI routing tools Learn More

Sync Interceptor

The ISyncInterceptor interface lets you modify HTTP requests before they are sent during pull and push operations. The most common use case is adding authentication headers.

public class MySyncInterceptor : ISyncInterceptor
{
readonly IAuthService _auth;
public MySyncInterceptor(IAuthService auth)
{
_auth = auth;
}
public async Task BeforePull(Type documentType, DateTimeOffset lastRun, HttpRequestMessage request)
{
var token = await _auth.GetAccessTokenAsync();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
public async Task BeforePush(Type documentType, object[] items, HttpRequestMessage request)
{
var token = await _auth.GetAccessTokenAsync();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
}

Register as a singleton in your DI container:

builder.Services.AddSingleton<ISyncInterceptor, MySyncInterceptor>();
MethodParametersDescription
BeforePullType documentType — the entity type being pulledCalled before each pull HTTP request
DateTimeOffset lastRun — when this entity type was last pulled
HttpRequestMessage request — the outgoing request to modify
BeforePushType documentType — the entity type being pushedCalled before each push HTTP request
object[] items — the entities about to be pushed
HttpRequestMessage request — the outgoing request to modify