public PredictionEngine <TInput, TPrediction> GetPredictionEngine(string modelName)
        {
            if (_namedPools.ContainsKey(modelName))
            {
                return(_namedPools[modelName].PredictionEnginePool.Get());
            }

            if (string.IsNullOrEmpty(modelName))
            {
                if (_defaultPool == null)
                {
                    throw new ArgumentException("You need to configure a default, not named, model before you use this method.");
                }

                return(_defaultPool.PredictionEnginePool.Get());
            }

            var options = _optionsFactory.Create(modelName);

            var pool = new ModelPoolLoader <TInput, TPrediction>(options);

            _namedPools.Add(modelName, pool);

            return(pool.PredictionEnginePool.Get());
        }
        public ModelPredictionEngine(
            IOptionsFactory <ModelPredictionEngineOptions <TInput, TPrediction> > optionsFactory,
            IOptions <MLContextOptions> mlContextOptions)
        {
            _optionsFactory = optionsFactory ?? throw new ArgumentNullException(nameof(optionsFactory));

            MLContext = mlContextOptions.Value.MLContext ?? throw new ArgumentNullException(nameof(mlContextOptions));

            var defaultOptions = _optionsFactory.Create(string.Empty);

            if (defaultOptions.CreateModel != null)
            {
                _defaultPool = new ModelPoolLoader <TInput, TPrediction>(defaultOptions);
            }

            _namedPools = new Dictionary <string, ModelPoolLoader <TInput, TPrediction> >();
        }