예제 #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IAmqpService amqpService, IApplicationLifetime applicationLifetime)
        {
            if (_hostingEnvironment.IsDevelopment() || _hostingEnvironment.IsEnvironment("DevelopmentServer"))
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            //loggerFactory.AddDebug();
            loggerFactory.AddLog4Net(Path.Combine(ContentRoot, "config/log4net.config"));

            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "SmartDevicesGatewayAPI");
            });

            //using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
            //{
            //    var dbContext = serviceScope.ServiceProvider.GetService<SmartdevicesGatewayDBContext>();

            //    var dbNewlyCreated = dbContext.Database.EnsureCreated();
            //}

            applicationLifetime.ApplicationStarted.Register(OnStarted);
            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            _app = app;
        }
예제 #2
0
파일: Startup.cs 프로젝트: matand/bankor
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddCors(a =>
                             a.AddPolicy("all", cpb =>
                                         cpb.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));

            var builder = new ClientBuilder()
                          .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "bancor-api";
            })
                          .ConfigureLogging(logging => logging.AddConsole());

            if (_hostingEnvironment.IsEnvironment("Integration"))
            {
                builder.UseConsulClustering(options =>
                {
                    options.Address = new Uri("http://consul:8500");
                });
            }
            else if (_hostingEnvironment.IsDevelopment())
            {
                builder.UseLocalhostClustering();
            }

            var client = builder.Build();

            client.Connect(RetryFilter).GetAwaiter().GetResult();

            //var clusterClient = ClientFactory.StartClientWithRetries().GetAwaiter().GetResult();

            services.AddSingleton <IClusterClient>(client);


            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Bancor API", Version = "v1"
                });
            });

            return(services.BuildServiceProvider());
        }
예제 #3
0
 public static ISiloHostBuilder ConfigureClustering(
     this ISiloHostBuilder builder, IHostingEnvironment hostingEnvironment)
 {
     if (hostingEnvironment.IsDevelopment())
     {
         return(builder.UseLocalhostClustering());
     }
     else if (hostingEnvironment.IsEnvironment("Compose"))
     {
         return(builder.UseComposeClustering("host"));
     }
     else
     {
         return(builder.UseKubeMembership(opt =>
         {
             opt.Group = "orleans.dot.net";
             opt.CanCreateResources = true;
         }));
     }
 }