Most .NET(Core) applications today use any kind of inversion of control. This is not different for a Microsoft Orleans application.
It leverages the ASP.NET Core built-in IoC container to allow you to inject dependencies in your grains:
This sounds really easy and in fact it is. The only thing you need to be aware of is that the Orleans application is NOT re-using the (ASP) .NET Core IoC container but uses it’s own instance. This is something I didn’t know and caused me a lot of headaches before I figured out the reason.
Microsoft Orleans is using similar concepts as ASP.NET Core but is not using the same builder. There are plans to integrate it directly when .NET Core 3.0 is released but at the moment of writing, you have to use a specific OrleansBuilder:
Important to notice in the code above is that the ConfigureServices() method you call here exposes a different IServicesCollection instance as the one used by ASP.NET Core.