/// <summary> /// 为应用添加 python 服务功能 /// </summary> /// <param name="serviceCollection">服务管理集合</param> /// <param name="setupAction">服务的可选配置</param> public static void AddPythonServices( this IServiceCollection serviceCollection, Action <PythonServicesOptions> setupAction) { if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); } serviceCollection.AddSingleton(typeof(IPythonServices), serviceProvider => { // First we let NodeServicesOptions take its defaults from the IServiceProvider, // then we let the developer override those options var options = new PythonServicesOptions(serviceProvider); setupAction(options); return(PythonServicesFactory.CreatePythonServices(options)); }); }
/// <summary> /// 创建 python 服务 /// </summary> /// <param name="options">python 服务可选配置</param> /// <returns></returns> public static IPythonServices CreatePythonServices(PythonServicesOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } var service = new PythonServicesImpl(options /*.NodeInstanceFactory*/); Console.CancelKeyPress += (sender, e) => { service.Stop(); }; AppDomain.CurrentDomain.ProcessExit += (sender, e) => { service.Stop(); }; return(service); }