Ejemplo 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());
Ejemplo n.º 2
0
 static IHostBuilder CreateDefaultHost(string[] _) => new HostBuilder()
 .ConfigureWebHostDefaults(webhostbuilder => {
     //注册成为oxygen服务节点
     webhostbuilder.StartOxygenServer <OxygenActorStartup>((config) => {
         config.Port = 80;
         config.PubSubCompentName     = "pubsub";
         config.StateStoreCompentName = "statestore";
         config.TracingHeaders        = "Authentication,AuthIgnore";
         config.UseCors = true;
     });
 })
 .ConfigureAppConfiguration((hostContext, config) =>
 {
     config.SetBasePath(Directory.GetCurrentDirectory());
     config.AddJsonFile("appsettings.json");
     Configuration = config.Build();
 })
 .ConfigureContainer <ContainerBuilder>(builder =>
 {
     //注入oxygen依赖
     builder.RegisterOxygenModule();
     //注入业务依赖
     builder.RegisterModule(new ServiceModule());
 })
 .ConfigureServices((context, services) =>
 {
     services.AddHttpClient();
     //注册自定义HostService
     services.AddHostedService <CustomerService>();
     //注册全局拦截器
     LocalMethodAopProvider.RegisterPipelineHandler(AopHandlerProvider.ContextHandler, AopHandlerProvider.BeforeSendHandler, AopHandlerProvider.AfterMethodInvkeHandler, AopHandlerProvider.ExceptionHandler);
     //注册鉴权拦截器
     AccountAuthenticationHandler.RegisterAllFilter();
     services.AddLogging(configure =>
     {
         configure.AddConfiguration(Configuration.GetSection("Logging"));
         configure.AddConsole();
     });
     services.AddDbContext <EfDbContext>(options => options.UseNpgsql(Configuration.GetSection("SqlConnectionString").Value));
     services.AddAutofac();
 })
 .UseServiceProviderFactory(new AutofacServiceProviderFactory());
Ejemplo n.º 3
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";
     });
 })
 .ConfigureAppConfiguration((hostContext, config) =>
 {
     config.SetBasePath(Directory.GetCurrentDirectory());
     config.AddJsonFile("appsettings.json");
     _configuration = config.Build();
 })
 .ConfigureContainer <ContainerBuilder>(builder =>
 {
     //×¢ÈëoxygenÒÀÀµ
     builder.RegisterOxygenModule();
     //×¢ÈëÒµÎñÒÀÀµ
     builder.RegisterModule(new ServiceModule());
 })
 .ConfigureServices((context, services) =>
 {
     //×¢²á×Ô¶¨ÒåHostService
     services.AddHostedService <CustomerService>();
     //×¢²áÈ«¾ÖÀ¹½ØÆ÷
     LocalMethodAopProvider.RegisterPipelineHandler(AopHandlerProvider.ContextHandler, AopHandlerProvider.BeforeSendHandler, AopHandlerProvider.AfterMethodInvkeHandler, AopHandlerProvider.ExceptionHandler);
     //×¢²á¼øȨÀ¹½ØÆ÷
     AuthenticationHandler.RegisterAllFilter();
     services.AddLogging(configure =>
     {
         configure.AddConfiguration(_configuration.GetSection("Logging"));
         configure.AddConsole();
     });
     services.AddDbContext <EfDbContext>(options => options.UseNpgsql(_configuration.GetSection("SqlConnectionString").Value));
     services.AddAutofac();
 })
 .UseServiceProviderFactory(new AutofacServiceProviderFactory());
Ejemplo n.º 4
0
 static IHostBuilder CreateDefaultHost(string[] args) => new HostBuilder()
 .ConfigureWebHostDefaults(webhostbuilder => {
     //注册成为oxygen服务节点
     webhostbuilder.StartOxygenServer <OxygenStartup>((config) => {
         config.Port = 80;
         config.PubSubCompentName     = "pubsub";
         config.StateStoreCompentName = "statestore";
         config.TracingHeaders        = "Authentication,AuthIgnore";
         config.UseStaticFiles        = true;
         config.UseCors = true;
     });
 })
 .ConfigureAppConfiguration((hostContext, config) =>
 {
     config.SetBasePath(Directory.GetCurrentDirectory());
     config.AddJsonFile("appsettings.json");
     _configuration = config.Build();
 })
 .ConfigureContainer <ContainerBuilder>(builder =>
 {
     //注入oxygen依赖
     builder.RegisterOxygenModule();
     //注入业务依赖
     builder.RegisterModule(new ServiceModule());
     builder.RegisterType <ImageAppService.ImageAppService>().As <IApplicationService.Base.IImageAppService>().InstancePerLifetimeScope();
 })
 .ConfigureServices((context, services) =>
 {
     //注册全局拦截器
     LocalMethodAopProvider.RegisterPipelineHandler(AopHandlerProvider.ContextHandler, AopHandlerProvider.BeforeSendHandler, AopHandlerProvider.AfterMethodInvkeHandler, AopHandlerProvider.ExceptionHandler);
     //注册鉴权拦截器
     ImageAuthenticationHandler.RegisterAllFilter();
     services.AddLogging(configure =>
     {
         configure.AddConfiguration(_configuration.GetSection("Logging"));
         configure.AddConsole();
     });
     services.AddAutofac();
 })
 .UseServiceProviderFactory(new AutofacServiceProviderFactory());