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.
Implementing ISyncInterceptor
Section titled “Implementing ISyncInterceptor”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); }}Registration
Section titled “Registration”Register as a singleton in your DI container:
builder.Services.AddSingleton<ISyncInterceptor, MySyncInterceptor>();Parameters
Section titled “Parameters”| Method | Parameters | Description |
|---|---|---|
BeforePull | Type documentType — the entity type being pulled | Called before each pull HTTP request |
DateTimeOffset lastRun — when this entity type was last pulled | ||
HttpRequestMessage request — the outgoing request to modify | ||
BeforePush | Type documentType — the entity type being pushed | Called before each push HTTP request |
object[] items — the entities about to be pushed | ||
HttpRequestMessage request — the outgoing request to modify |