Orleans dependency injection

I’m not sure how and where to add dependencies to the grain. Where is the best place for this?

If this is not possible, should I create a container in the WorkerRole.Run method and get instances when I need them?

+6
source share
2 answers

There is limited support for DI beans. This function promises to be delivered shortly, but, as in 1.0.9, there is no traditional constructor injection.

Until now, you can use the (anti-pattern) ServiceLocator using the frameworks of your choice (for example, for this we use Autofac and CommonServiceLocator) to solve the services that you want to call inside your grain instance.

For unit testing - there is a Grain constructor that you can use to create an instance of grain using mocks (see more details here )

I invite you to a conversation with the orchestra in Orleans (as in the link above), where you can see answers and discussions around some other burning questions.

+7
source

Since orleans 1.1.0 , the 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

+10
source

All Articles