I'm not sure how or where to inject dependencies into a Grain. Where's the best place to do this?
If it's not possible, should I set up a container in the WorkerRole.Run method and get instances as I need them?
Since orleans 1.1.0 release, orleans team added "ASP.NET vNext style Dependency Injection for grains", you can see an example of this in here
Also to see how "ASP.NET vNext Dependency Injection" works see here
There is a limited support for DI in the grains. This feature is being promised to be delivered soon , but as in 1.0.9 - there is no traditional constructor injection.
So far you can use (anti-pattern) ServiceLocator using frameworks of your choice (e.g we are using Autofac and CommonServiceLocator for that) for resolving services you want to call inside your grain instance.
For the unit testing - there is a Grain constructor which can be used to construct grain instance with mocks (see more details here )
I'd invite you to the Orleans gitter chat (as via link above) where you can see answers and discussions around some other burning questions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With