private static void StartApp(string[] args)
        {
            MyAppConfig.SetEnvironmentVariables("consoleback");

            var config = Host.CreateDefaultBuilder(args)
                         .ConfigureAppConfiguration(MyAppConfig.Configure)
                         .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration))
                         .Build().Services.GetRequiredService <IConfiguration>();

            var serlogger = config.CreateSerilogger();

            Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration(MyAppConfig.Configure)
            .ConfigureServices((context, services) =>
            {
                var sopiBuilder = services
                                  .AddSopi(context.Configuration, serlogger.Information)
                                  .AddPlatformServices()
                                  .AddSystemServicesByConfiguration()
                ;


                sopiBuilder
                .AddDomainServices();

                services
                .AddSingleton <ISaga, MySaga>()


                .AddHostedService <SopiAppService>()

                ;
            })
            .Build().Run()
            ;
        }
Exemple #2
0
        private static IHostBuilder CreateWebHostBuilder(string[] args)
        {
            MyAppConfig.SetEnvironmentVariables("fronthost");
            MyAppConfig.SetWebSocketEnvironmentVariables(Constants.NotificationsBaseRouteAuth);

            var config = WebHost.CreateDefaultBuilder(args)
                         .ConfigureAppConfiguration(MyAppConfig.Configure)
                         .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration))
                         .Configure(builder => { })
                         .Build().Services.GetRequiredService <IConfiguration>();

            var serlogger = config.CreateSerilogger();

            return(Host.CreateDefaultBuilder(args)
                   .ConfigureAppConfiguration(MyAppConfig.Configure)
                   .UseSerilog()
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureServices((context, services) =>
                {
                    var sopiBuilder = services
                                      .AddSopi(context.Configuration, serlogger.Information)
                                      .AddAuthentication()
                                      .AddPlatformServices()
                                      .AddMvcServices(mvc =>
                    {
                        mvc.AddNewtonsoftJson();
                    })
                                      .AddSystemServicesByConfiguration()
                    ;

                    services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle,
                                                               Constants.ApiBaseRoute,
                                                               "sample",
                                                               new[]
                    {
                        Constants.ApiKey, "api", "api2", "cmd1", "qry1"
                    },
                                                               false, options =>
                    {
                        options.SchemaFilter <RemoveAllOffSchemaFilter>();
                    }, sopiBuilder.Log);


                    services
                    .AddTestClientOptions(c => { c.BaseAddress = "http://localhost:5097"; })
                    .AddTestSystemClient()
                    .AddTestUserClient()
                    ;

                    services
                    .AddSignalR(options => { options.EnableDetailedErrors = true; })
                    .AddJsonProtocol()
                    .AddNewtonsoftJsonProtocol()
                    .AddMessagePackProtocol()
                    ;


                    services
                    .AddTransient <MyQueryService>()
                    ;


                    sopiBuilder.GetMvcBuilder().AddApplicationPart(typeof(HomeController).Assembly);
                });

                webBuilder.Configure(app =>
                {
                    var logger = app.ApplicationServices.GetStartupLogger();
                    app.UseSerilogRequestLogging();

                    app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s));
                    app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s));

                    app.UseRouting()
                    .UseAuthentication()
                    .UseAuthorization();

                    app.UseEndpoints(endpoints =>
                    {
                        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

                        endpoints.MapHub <TestHub>(Constants.NotificationsBaseRoute);
                        endpoints.MapHub <TestHubAuth>(Constants.NotificationsBaseRouteAuth);
                    })
                    .UseSopiSwagger();
                });
            })
                   );
        }
Exemple #3
0
        private static IHostBuilder CreateWebHostBuilder(string[] args)
        {
            var id = "backhost";

            MyAppConfig.SetEnvironmentVariables(id);

            var config = WebHost.CreateDefaultBuilder(args)
                         .ConfigureAppConfiguration(MyAppConfig.Configure)
                         .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration))
                         .Configure(builder => { })
                         .Build().Services.GetRequiredService <IConfiguration>();
            var serlogger = config.CreateSerilogger();

            return(Host.CreateDefaultBuilder(args)
                   .ConfigureAppConfiguration(MyAppConfig.Configure)
                   .UseSerilog()
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureServices((context, services) =>
                {
                    var sopiBuilder = services
                                      .AddSopi(context.Configuration, serlogger.Information)
                                      .AddAuthentication()
                                      .AddPlatformServices()
                                      .AddMvcServices(mvc =>
                    {
                        mvc.AddNewtonsoftJson();
                    })
                                      .AddSystemServicesByConfiguration()
                    ;

                    sopiBuilder
                    .AddDomainServices();

                    services
                    .AddSingleton <ISaga, MySaga1>();


                    sopiBuilder
                    .AddProjectionServices();


                    services
                    .AddSingleton <MyProjector1>()
                    .AddSingleton <IReadModelProjector, MyCompositeProjector1>()

                    .AddHostedService <SopiAppService>()
                    ;


                    services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle,
                                                               Constants.ApiBaseRoute,
                                                               "backhost",
                                                               new[]
                    {
                        Constants.ApiKey, "api", "api2", "cmd1", "qry1"
                    },
                                                               false, options =>
                    {
                        options.SchemaFilter <RemoveAllOffSchemaFilter>();
                    }, sopiBuilder.Log);
                });

                webBuilder.Configure(app =>
                {
                    var logger = app.ApplicationServices.GetStartupLogger();
                    app.UseSerilogRequestLogging();

                    app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s));
                    app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s));
                    app.UseProjectionStatusEndpoint(Constants.ProjectionBaseRoute, s => logger.LogInformation(s));


                    app.UseRouting()
                    .UseAuthentication()
                    .UseAuthorization();
                });
            })
                   );
        }
        private static IHostBuilder CreateWebHostBuilder(string[] args)
        {
            var id = Environment.GetEnvironmentVariable("APPID");

            if (string.IsNullOrEmpty(id))
            {
                id = "app";
            }

            MyAppConfig.SetEnvironmentVariables(id);
            MyAppConfig.SetWebSocketEnvironmentVariables(Constants.NotificationsBaseRouteAuth);

            var config = WebHost.CreateDefaultBuilder(args)
                         .ConfigureAppConfiguration(MyAppConfig.Configure)
                         .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration))
                         .Configure(builder => { })
                         .Build().Services.GetRequiredService <IConfiguration>();


            var serlogger = config.CreateSerilogger();

            return(Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
                   .ConfigureAppConfiguration(MyAppConfig.Configure)
                   .UseSerilog()
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureServices((context, services) =>
                {
                    var sopiBuilder = services
                                      .AddSopi(context.Configuration, serlogger.Information)
                                      .AddAuthentication()
                                      .AddPlatformServices()
                                      .AddMvcServices(mvc =>
                    {
                        mvc.AddNewtonsoftJson();
                    })
                                      .AddSystemServicesByConfiguration()
                    ;

                    var startDomainServices = Environment.GetEnvironmentVariable("DOMAIN_SERVICES");

                    if (string.IsNullOrEmpty(startDomainServices) || startDomainServices.ToLower() == "true")
                    {
                        sopiBuilder
                        .AddDomainServices();

                        services
                        .AddSingleton <ISaga, MySaga1>();
                    }

                    var startProjectionServices = Environment.GetEnvironmentVariable("PROJECTION_SERVICES");

                    if (string.IsNullOrEmpty(startProjectionServices) || startProjectionServices.ToLower() == "true")
                    {
                        sopiBuilder
                        .AddProjectionServices();

                        services
                        .AddSingleton <MyProjector1>()
                        .AddSingleton <IReadModelProjector, MyCompositeProjector1>();
                    }

                    services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle,
                                                               Constants.ApiBaseRoute,
                                                               "sample",
                                                               new[]
                    {
                        Constants.ApiKey, "api", "api2", "cmd1", "qry1"
                    },
                                                               false, options =>
                    {
                        options.SchemaFilter <RemoveAllOffSchemaFilter>();
                    }, sopiBuilder.Log);

                    services
                    .AddTestClientOptions(c => { c.BaseAddress = "http://localhost:5099"; })
                    .AddTestSystemClient()
                    .AddTestUserClient()
                    .AddSingleton <IReadModelProjector, MyProjector1>()
                    .AddSopiService <DelayStartService>()
                    .AddHostedService <SopiAppService>()
                    ;



                    services.AddSignalR(options => { options.EnableDetailedErrors = true; })
                    ;

                    var startQueryServices = Environment.GetEnvironmentVariable("QUERY_SERVICES");

                    if (string.IsNullOrEmpty(startQueryServices) || startQueryServices.ToLower() == "true")
                    {
                        services
                        .AddTransient <MyQueryService>()
                        ;
                    }

                    sopiBuilder.GetMvcBuilder().AddApplicationPart(typeof(HomeController).Assembly);
                });


                webBuilder.Configure(app =>
                {
                    var logger = app.ApplicationServices.GetStartupLogger();
                    app.UseSerilogRequestLogging();

                    app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s));
                    app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s));
                    app.UseProjectionStatusEndpoint(Constants.ProjectionBaseRoute, s => logger.LogInformation(s));

                    app.UseRouting()
                    .UseAuthentication()
                    .UseAuthorization();

                    app.UseEndpoints(endpoints =>
                    {
                        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

                        endpoints.MapHub <TestHub>(Constants.NotificationsBaseRoute);
                        endpoints.MapHub <TestHubAuth>(Constants.NotificationsBaseRouteAuth);
                    })
                    .UseSopiSwagger();
                });
            }));
        }