static async Task Main(string[] args) { var host = new ServiceHost(); host.AddJsonConfiguration("Config.json", reloadOnChange: true); host.ConfigureLogging(builder => builder.UserNLog()); host.ConfigureContainer(builder => { builder.Register(c => new LoggerInterceptor(invocation => ( $"{invocation.TargetType.Name}InvokeLog", LogLevel.Debug, "\n========================================\n" + $"Method:\t{invocation.Method}\n" + $"Args:\t{string.Join('|', invocation.Arguments)}\n" + $"Return:\t{invocation.ReturnValue}\n" + "========================================" ))); builder.RegisterType <A>().As <I>().EnableInterfaceInterceptors(); builder.RegisterType <B>().As <I>().EnableInterfaceInterceptors(); }); host.OnHostStarted += provider => { ServiceHost.ParseConfiguration <string>("ConnectionString"); foreach (var item in provider.GetServices <I>()) { item.Do(5, 6); } }; await host.RunAsync(); }
static async Task Main(string[] args) { var host = new ServiceHost(); host.AddJsonConfiguration("Config.json"); host.ConfigureRabbitMQ("MQ"); host.OnHostStarted += p => { var s = p.GetRabbitMQ(); // 创建交换机 s.ExchangeDeclare("exchange.direct", ExchangeType.Direct); // 创建队列 s.QueueDeclare("queueA", true); // 绑定 s.QueueBind("queueA", "exchange.direct", "A"); // 订阅 s.Subscribe("queueA", true, (m, a) => Console.WriteLine(Encoding.UTF8.GetString(a.Body.ToArray()))); // 发布消息 s.Publish(new { Id = 1, Name = "Joy" }, "exchange.direct", "A"); }; await host.RunAsync(); }
static async Task Main(string[] args) { var host = new ServiceHost(); // 可在运行时修改配置文件 host.AddJsonConfiguration("Config.json", reloadOnChange: true); host.ConfigureSqlSugar(); host.ConfigureLogging(builder => builder.UserNLog()); host.OnHostStarted += p => { var s = p.GetSqlSugar(); var c = s.CreateConnection("Main"); var d = c.DbMaintenance.GetTableInfoList(); }; await host.RunAsync(); }
/// <summary> /// 配置SqlSugar /// </summary> /// <param name="host"></param> /// <param name="stream"></param> /// <param name="path"></param> /// <returns></returns> public static ServiceHost ConfigureSqlSugarWithJson(this ServiceHost host, Stream stream, string path = null) { host.AddJsonConfiguration(stream); return(host.ConfigureSqlSugar(path)); }
/// <summary> /// 配置SqlSugar /// </summary> /// <param name="host"></param> /// <param name="file"></param> /// <param name="path"></param> /// <returns></returns> public static ServiceHost ConfigureSqlSugarWithJson(this ServiceHost host, string file, string path = null) { host.AddJsonConfiguration(file, reloadOnChange: true); return(host.ConfigureSqlSugar(path)); }