dotnet/orleans

GrainFactory in IIncomingGrainCallContext

meisamhasani opened this issue · 3 comments

hello
how do i have GrainFactory forcall grains into a :
Task Invoke(IIncomingGrainCallContext context)

Hello @meisamhasani,

when discussing grains interceptors, there are multiple ways to access the GrainFactory from the Invoke method.

  1. If Call Filter is being implemented on the Grain level, you can simply use GrainFactory from base grain class.
  2. If Call Filter is silo-wide, then it is possible to:
    2.1. inject GrainFactory using DI;
    2.2. get GrainFactory from IServiceProvider, that can be accessed via IGrainContext:
IGrainFactory grainFactory = context.TargetContext.ActivationServices.GetService<IGrainFactory>();

Warning

Be cautious when calling grains from an interceptor, as you might encounter deadlocks or recursion. For example,

  1. calling Grain A
  2. executing interceptor for Grain A
  3. calling Grain B from interceptor
  4. executing interceptor for Grain B

If you still have questions, please provide more details about your problem and share a code snippet.

@ivanvyd great answer!