From a5817d7149bc9d85767aa6a2c8474a9099e5a88f Mon Sep 17 00:00:00 2001 From: rkargMsft <164392675+rkargMsft@users.noreply.github.com> Date: Thu, 19 Mar 2026 07:55:23 -0700 Subject: [PATCH] Document RequestContext access in placement and placement filtering Added example code for accessing RequestContext data during placement filtering. --- docs/orleans/grains/request-context.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/orleans/grains/request-context.md b/docs/orleans/grains/request-context.md index 66abf04f124b7..71e41873ecf14 100644 --- a/docs/orleans/grains/request-context.md +++ b/docs/orleans/grains/request-context.md @@ -114,3 +114,28 @@ Console.WriteLine(message); ``` In this example, the client sets the trace ID to "example-id-set-by-client" before calling the `SayHello` method on the `HelloGrain`. The grain retrieves the trace ID from the request context and logs it. + +## Example placement access code + +The data can be accessed during Placement or Placement Filtering through the `RequestContextData`. The static is not populated at this time as there is not yet an activation of the grain. The following placement filter code demonstrates how to get data while handling placement: + +```csharp +internal sealed class ExamplePlacementFilterDirector(ILogger logger) + : IPlacementFilterDirector +{ + public IEnumerable Filter( + PlacementFilterStrategy filterStrategy, + PlacementTarget target, + IEnumerable silos) + { + if (target.RequestContextData.TryGetValue("somekey", out var somevalue) + && somevalue is string somestring) + { + logger.LogInformation("Read {Value} for {Key} from the RequestContext", somestring, "somekey"); + // somestring is available for the filtering logic + } + return silos; + } +} +``` +In this example, the "somekey" value is read from the `RequestContextData` during the placement filtering.