Dependency injection with Orleans
Asked Answered
T

2

6

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?

Tautologism answered 1/9, 2015 at 2:54 Comment(1)
It seems DI support was added to Orleans, but it's not yet in any released version.Waterway
A
7

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.

Auckland answered 1/9, 2015 at 10:30 Comment(0)
A
10

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

Aristocrat answered 6/1, 2016 at 10:6 Comment(0)
A
7

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.

Auckland answered 1/9, 2015 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.