Exemple #1
0
        /// <summary>
        /// 启动主流程控制器,发现指定程序集的Api,适用于测试的场景
        /// </summary>
        /// <param name="services">依赖服务</param>
        /// <param name="assembly">需要发现服务的程序集</param>
        public static async Task UseTest(this IServiceCollection services, Assembly assembly = null)
        {
            if (Interlocked.Increment(ref isInitialized) != 1)
            {
                return;
            }
            services.TryAddTransient <IServiceReceiver, EmptyReceiver>();
            services.TryAddTransient <IMessageConsumer, EmptyReceiver>();
            services.TryAddTransient <INetEvent, EmptyReceiver>();
            AddDependency(services);
            //ZeroFlowControl.Check();
            //ZeroFlowControl.Discove(assembly);
            //ZeroFlowControl.Check();
            //if (assembly != null)
            //    ZeroFlowControl.Discove(assembly);
            await ZeroFlowControl.Initialize();

            await ZeroFlowControl.RunAsync();
        }
        async Task IHostedService.StartAsync(CancellationToken cancellationToken)
        {
            _tokenSource = new CancellationTokenSource();
            _appLifetime.ApplicationStarted.Register(() => ZeroFlowControl.OnStarted(_tokenSource));
            _appLifetime.ApplicationStopping.Register(() => ZeroFlowControl.OnStopping(_tokenSource));

            ZeroFlowControl.Logger = _logger;
            await ZeroFlowControl.CheckConfig();

            if (ZeroAppOption.Instance.AutoDiscover)
            {
                ZeroFlowControl.Discove();
            }
            ZeroAppOption.Instance.Discovery?.Invoke();

            ZeroFlowControl.Discove();
            await ZeroFlowControl.Initialize();

            await ZeroFlowControl.RunAsync();
        }