dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.07k stars 2.03k forks source link

GetGrain() chooses an arbitrary implementation in case of multiple #8601

Closed ugumba closed 11 months ago

ugumba commented 1 year ago

I'm in a situation where I need to support an alternative grain implementation for some activations.

According to this (old) answer, GetGrain() should just fail by default, in the presence of multiple implementations.

Using 7.2.1, this is not the case. The runtime seems to activate an instance of one particular implementation, probably chosen by FirstOrDefault() from GrainTypeOptions.Classes. (If so, as this is HashSet, the result is undefined.)

Not a bug as such, as I must augment my call to GetGrain() with grainClassNamePrefix regardless, but it's a bit odd to allow undefined behaviour. Is this intentional, or is there a selection/prioritization mechanism I'm not aware of?

ReubenBond commented 1 year ago

Does one of your grains match the interface name by dropping the I, perhaps? eg, MyGrain : IMyGrain, whereas the other is MyOtherGrain : IMyGrain? If so, I believe that was always the expected behavior (despite my answer on SO). When there are two grains which do not match the interface name (class name is interface name without the I), then it should throw and indicate that the name is ambiguous.

ugumba commented 1 year ago

Ah, thanks - that was it! I now vaguely recall reading this factoid before, but couldn't find it from browsing the docs.
Feel free to close if it is documented.