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); }
/// <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); } }
public IocManager(SpearBootstrap bootstrap) { _bootstrap = bootstrap; }