orleans icon indicating copy to clipboard operation
orleans copied to clipboard

How to use dependency injection to inject services grains?

Open richcorless opened this issue 10 years ago • 2 comments

Hi,

There are a number of mentions of using DI to inject services into grains and being able to use your preferred container, just not how. Could someone point me in the direction of some sample code, tutorial, or hints of where to begin please?

Thanks, Rich

richcorless avatar Aug 02 '16 16:08 richcorless

Orleans uses Microsoft.Framework.DependencyInjection

When building your cluster configuration, you can set the type that will handle your registration:

clusterConfig.Defaults.StartupTypeName = typeof(ServiceRegistration).AssemblyQualifiedName;

In that class, just make sure to have a method with the following signature:

public IServiceProvider ConfigureServices(IServiceCollection services)

From there you can register what you need using your container of choice.

Full example/test can be found here.

kwal avatar Aug 03 '16 01:08 kwal

Hi Kwal,

Thank you, that's exactly what I needed. Have it working with SimpleInjector now.

Rich

richcorless avatar Aug 03 '16 09:08 richcorless