コード例 #1
0
        private void Init()
        {
            var services = new ServiceCollection();

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

            MapServices(services);
            Bootstrap = new SpearBootstrap();
            Bootstrap.BuilderHandler += builder =>
            {
                builder.Populate(services);
                MapServices(builder);
            };
            Bootstrap.Initialize();
            var container = Bootstrap.CreateContainer();
            var provider  = new AutofacServiceProvider(container);

            UseServices(provider);
        }
コード例 #2
0
ファイル: ConsoleHost.cs プロジェクト: yuyixiaoxiang/spear
        /// <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);
            }
        }
コード例 #3
0
ファイル: IocManager.cs プロジェクト: yuyixiaoxiang/spear
 public IocManager(SpearBootstrap bootstrap)
 {
     _bootstrap = bootstrap;
 }