WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
84
Events-WebApi/Events.WebAPI/Program.cs
Normal file
84
Events-WebApi/Events.WebAPI/Program.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Reflection;
|
||||
using AutoMapper;
|
||||
using Events.WebAPI;
|
||||
using Events.WebAPI.Contract.Validation.Sport;
|
||||
using Events.WebAPI.Contract.Validation;
|
||||
using Events.WebAPI.Handlers.EF.Mappings;
|
||||
using Events.WebAPI.Handlers.EF.QueryHandlers;
|
||||
using Events.WebAPI.Handlers.EF.Data.Postgres;
|
||||
using Events.WebAPI.Util.Extensions;
|
||||
using Events.WebAPI.Util.Startup;
|
||||
using Events.WebAPI.Util.Swagger;
|
||||
using Events.WebAPI.Util.Validation;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services
|
||||
.AddControllers(options => options.AddJsonPatchSupport())
|
||||
.AddJsonOptions(configure => configure.JsonSerializerOptions.PropertyNamingPolicy = null);
|
||||
|
||||
builder.Services.AddDbContext<EventsContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("EventDB")));
|
||||
|
||||
builder.Services.Configure<SieveOptions>(builder.Configuration.GetSection("Sieve"));
|
||||
builder.Services.AddScoped<ISieveProcessor, SieveProcessor>();
|
||||
builder.Services.AddScoped<IValidationMessageProvider, ValidationMessageProvider>();
|
||||
|
||||
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
|
||||
builder.Services.AddValidatorsFromAssemblyContaining(typeof(AddSportValidator));
|
||||
builder.Services.AddMediatR(cfg => {
|
||||
cfg.RegisterServicesFromAssembly(typeof(SportsQueryHandler).Assembly);
|
||||
});
|
||||
|
||||
builder.Services.SetupMassTransit(builder.Configuration);
|
||||
builder.Services.SetupAuthenticationAndAuthorization(builder.Configuration);
|
||||
|
||||
#region AutoMapper settings
|
||||
Action<IServiceProvider, IMapperConfigurationExpression> mapperConfigAction = (serviceProvider, cfg) =>
|
||||
{
|
||||
cfg.ConstructServicesUsing(serviceProvider.GetService);
|
||||
};
|
||||
builder.Services.AddAutoMapper(mapperConfigAction, typeof(EFMappingProfile)); //assemblies containing mapping profiles
|
||||
#endregion
|
||||
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc(Constants.ApiVersion, new OpenApiInfo { Title = "Events API", Version = Constants.ApiVersion });
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
if (File.Exists(xmlPath))
|
||||
c.IncludeXmlComments(xmlPath);
|
||||
c.AddBearerTokenScheme();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.RoutePrefix = "docs";
|
||||
c.DocumentTitle = "Events WebApi";
|
||||
c.SwaggerEndpoint($"../swagger/{Constants.ApiVersion}/swagger.json", "Events WebAPI");
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCors(builder =>
|
||||
{
|
||||
builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.WithExposedHeaders("Token-Expired", "Content-Disposition");
|
||||
});
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user