Exemplo n.º 1
0
 static IHostBuilder CreateDefaultHost(string[] args) => new HostBuilder()
 .ConfigureWebHostDefaults(webhostbuilder => {
     //注册成为oxygen服务节点
     webhostbuilder.StartOxygenServer <OxygenActorStartup>((config) => {
         config.Port = 80;
         config.PubSubCompentName     = "pubsub";
         config.StateStoreCompentName = "statestore";
         config.TracingHeaders        = "Authentication";
     });
 })
 .ConfigureContainer <ContainerBuilder>(builder =>
 {
     //注入oxygen依赖
     builder.RegisterOxygenModule();
     //注入测试demo
     builder.RegisterType <HelloServiceImpl>().As <IHelloService>().InstancePerLifetimeScope();
     builder.RegisterType <HelloEventHandler>().As <HelloEventHandler>().InstancePerLifetimeScope();
 })
 .ConfigureLogging((hostingContext, logging) => {
     logging.AddConsole();
 })
 .ConfigureServices((context, services) =>
 {
     //注册全局拦截器
     LocalMethodAopProvider.RegisterPipelineHandler((methodctx) => {
         HttpContextCurrent.SetCurrent(methodctx);
     }, async(obj, methodctx) =>
     {
         if (obj != null)
         {
             Console.WriteLine($"这里是方法前拦截器,拦截到参数:{JsonSerializer.Serialize(obj)}");
         }
         await Task.CompletedTask;
         var s = HttpContextCurrent.GetCurrent();
     }, async(result) =>
     {
         Console.WriteLine($"这里是方法后拦截器,拦截到方法结果:{JsonSerializer.Serialize(result)}");
         var s = HttpContextCurrent.GetCurrent();
         await Task.CompletedTask;
     }, async(exp) =>
     {
         Console.WriteLine($"这里是方法异常拦截器,拦截到异常:{exp.Message}");
         return(await Task.FromResult(new { Message = exp.Message }));
     });
     services.AddAutofac();
 })
 .UseServiceProviderFactory(new AutofacServiceProviderFactory());
Exemplo n.º 2
0
 public async Task <dynamic> GetHtml()
 {
     HttpContextCurrent.GetCurrent().HttpResponse.Cookies.Append("aaa", "bbb");
     HttpContextCurrent.GetCurrent().HttpResponse.Redirect("http://www.baidu.com");
     return(await Task.FromResult(""));
 }