-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
If a custom ModelLoader is used for the PredictionEnginePool that has a dependency on a configured service, there is no possibility to add this dependency via AddPredictionEnginePool as it does not offer an overload that accepts an implementation factory, unlike AddSingleton, AddScoped and AddTransient.
This is how it should be expected to happen in Startup:
services.AddPredictionEnginePool<Foo, Bar>(serviceProvider =>
{
services.AddOptions<PredictionEnginePoolOptions<Foo, Bar>>().Configure(options =>
{
options.ModelLoader = new MyModelLoader(serviceProvider.GetService<IMyService>());
});
return new PredictionEnginePool<Foo, Bar>();
});
Since this is not possible with the current code, the creation of a model via middleware is therefore very difficult. The only option is to use ServiceProvider.BuildServiceProvider which causes a warning as it results in an additional copy of singleton services being created:
services.AddPredictionEnginePool<Foo, Bar>()
services.AddOptions<PredictionEnginePoolOptions<Foo, Bar>>().Configure(options =>
{
var serviceProvider = services.BuildServiceProvider();
options.ModelLoader = new MyModelLoader(serviceProvider.GetService<IMyService>());
});
A new AddPredictionEnginePool overload should be added that accepts an implementation factory delegate to allow middleware services to be accessed via the IServiceProvider.