GrainFactory in IIncomingGrainCallContext
meisamhasani opened this issue · 3 comments
meisamhasani commented
hello
how do i have GrainFactory forcall grains into a :
Task Invoke(IIncomingGrainCallContext context)
ivanvyd commented
Hello @meisamhasani,
when discussing grains interceptors, there are multiple ways to access the GrainFactory from the Invoke method.
- If Call Filter is being implemented on the
Grain
level, you can simply useGrainFactory
from base grain class. - If Call Filter is silo-wide, then it is possible to:
2.1. injectGrainFactory
using DI;
2.2. getGrainFactory
fromIServiceProvider
, that can be accessed viaIGrainContext
:
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,
- calling Grain A
- executing interceptor for Grain A
- calling Grain B from interceptor
- executing interceptor for Grain B
If you still have questions, please provide more details about your problem and share a code snippet.
ReubenBond commented
@ivanvyd great answer!
meisamhasani commented
thank you @ivanvyd