Esempio n. 1
0
        /// <summary> 开启服务 </summary>
        /// <param name="args"></param>
        protected static void Start(string[] args)
        {
            Bootstrap = new SpearBootstrap();
            var services = new ServiceCollection();

            services.AddSpearConfig(ConfigBuild);

            services.AddLogging(builder =>
            {
                builder.AddConfiguration(ConfigHelper.Instance.Config.GetSection("Logging"));
                builder.AddConsole();
            });

            MapServiceCollection?.Invoke(services);
            Bootstrap.BuilderHandler += b =>
            {
                b.Populate(services);
                MapServices?.Invoke(b);
            };
            Bootstrap.Initialize();
            var container = Bootstrap.CreateContainer();

            if (UseServiceProvider != null)
            {
                var provider = new AutofacServiceProvider(container);
                UseServiceProvider.Invoke(provider);
            }

            UseServices?.Invoke(container);
            AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
            {
                Shutdown();
            };
            Console.CancelKeyPress += (sender, e) =>
            {
                Shutdown();
            };
            while (true)
            {
                var cmd = Console.ReadLine();
                if (cmd == "exit")
                {
                    break;
                }
                Command?.Invoke(cmd, container);
            }
        }