As mentioned in a previous post, it is not that hard to start using dependency injection with Orleans. But what if you don’t want to use the built-in IoC container?
To switch the IoC container instance you can call the UseServiceProviderFactory() method exposed by the SiloHostBuilder. Here is an example that uses StructureMap:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.UseServiceProviderFactory(services => | |
{ | |
var container = new Container(_ => | |
{ | |
_.For<IProductRepository>().Use<ProductRepository>().Singleton(); | |
}); | |
container.Populate(services); | |
return container.GetInstance<IServiceProvider>(); | |
}) |