コード例 #1
0
 public OrderController(
     OrderApiConfiguration configuration,
     IOrderReader orderReader,
     ICommandQueueClient queueClient)
 {
     _configuration = configuration;
     _orderReader   = orderReader;
     _queueClient   = queueClient;
 }
コード例 #2
0
ファイル: Startup.cs プロジェクト: RingLeaderSolutions/tp-api
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var orderApiConfiguration = new OrderApiConfiguration();

            Configuration.GetSection("OrderAPI").Bind(orderApiConfiguration);
            services.AddSingleton(orderApiConfiguration);

            ConfigureEventStore(services);
            ConfigureServiceBus(services);

            services.AddSingleton <IOrderReader, OrderReader>();
            services.AddSingleton <IHostedService, OrderService>();

            // TODO - vault name automatically determined via convention + detection of environment name
            services.AddTransient <IVault, Vault>(x => new Vault("theta-dev-platform-vault"));

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

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

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            services.AddHealthChecks()
            .AddCheck("self", () => running ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy())
            .AddAsyncCheck("dummy-dependency", async() => { await Task.Delay(2000); return(HealthCheckResult.Healthy()); }, new[] { "dependency" });
        }