You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace store
|
|
{
|
|
public class Startup
|
|
{
|
|
private readonly JsonSerializerOptions options = new JsonSerializerOptions()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
};
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
services.AddDaprClient(client =>
|
|
{
|
|
client.UseJsonSerializationOptions(options);
|
|
});
|
|
|
|
services.AddSingleton<OrdersEventBroker>();
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseCloudEvents();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapBlazorHub();
|
|
endpoints.MapFallbackToPage("/_Host");
|
|
|
|
endpoints.MapSubscribeHandler();
|
|
|
|
var broker = endpoints.ServiceProvider.GetRequiredService<OrdersEventBroker>();
|
|
endpoints.MapPost("/orderprocessed", async context =>
|
|
{
|
|
var confirmation = await JsonSerializer.DeserializeAsync<OrderConfirmation>(context.Request.Body, new JsonSerializerOptions()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
});
|
|
broker.Complete(confirmation);
|
|
}).WithTopic("messagebus", "orderprocessed");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|