|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Reflection; |
4 | 3 | using Conduit; |
5 | | -using Conduit.Features.Profiles; |
6 | 4 | using Conduit.Infrastructure; |
7 | 5 | using Conduit.Infrastructure.Errors; |
8 | | -using Conduit.Infrastructure.Security; |
9 | | -using FluentValidation; |
10 | | -using FluentValidation.AspNetCore; |
11 | | -using MediatR; |
12 | 6 | using Microsoft.AspNetCore.Builder; |
13 | | -using Microsoft.AspNetCore.Http; |
14 | 7 | using Microsoft.EntityFrameworkCore; |
15 | | -using Microsoft.Extensions.Configuration; |
16 | 8 | using Microsoft.Extensions.DependencyInjection; |
17 | 9 | using Microsoft.Extensions.Logging; |
18 | 10 | using Microsoft.OpenApi.Models; |
|
25 | 17 |
|
26 | 18 | var builder = WebApplication.CreateBuilder(args); |
27 | 19 |
|
28 | | -builder.Services.AddMediatR(cfg => |
29 | | - cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()) |
30 | | -); |
31 | | -builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>)); |
32 | | -builder.Services.AddScoped( |
33 | | - typeof(IPipelineBehavior<,>), |
34 | | - typeof(DBContextTransactionPipelineBehavior<,>) |
35 | | -); |
36 | | - |
37 | 20 | // take the connection string from the environment variable or use hard-coded database name |
38 | 21 | var connectionString = defaultDatabaseConnectionSrting; |
39 | 22 |
|
|
81 | 64 | x.SupportNonNullableReferenceTypes(); |
82 | 65 |
|
83 | 66 | x.AddSecurityRequirement( |
84 | | - new OpenApiSecurityRequirement() |
| 67 | + new OpenApiSecurityRequirement |
85 | 68 | { |
86 | 69 | { |
87 | 70 | new OpenApiSecurityScheme |
|
98 | 81 | ); |
99 | 82 | x.SwaggerDoc("v1", new OpenApiInfo { Title = "RealWorld API", Version = "v1" }); |
100 | 83 | x.CustomSchemaIds(y => y.FullName); |
101 | | - x.DocInclusionPredicate((version, apiDescription) => true); |
102 | | - x.TagActionsBy(y => new List<string>() |
| 84 | + x.DocInclusionPredicate((_, _) => true); |
| 85 | + x.TagActionsBy(y => new List<string> |
103 | 86 | { |
104 | 87 | y.GroupName ?? throw new InvalidOperationException() |
105 | 88 | }); |
|
123 | 106 | .WhenWritingNull |
124 | 107 | ); |
125 | 108 |
|
126 | | -builder.Services.AddFluentValidationAutoValidation(); |
127 | | -builder.Services.AddFluentValidationClientsideAdapters(); |
128 | | -builder.Services.AddValidatorsFromAssemblyContaining<Startup>(); |
129 | | - |
130 | | -builder.Services.AddAutoMapper(typeof(Program)); |
131 | | - |
132 | | -builder.Services.AddScoped<IPasswordHasher, PasswordHasher>(); |
133 | | -builder.Services.AddScoped<IJwtTokenGenerator, JwtTokenGenerator>(); |
134 | | -builder.Services.AddScoped<ICurrentUserAccessor, CurrentUserAccessor>(); |
135 | | -builder.Services.AddScoped<IProfileReader, ProfileReader>(); |
136 | | -builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| 109 | +builder.Services.AddConduit(); |
137 | 110 |
|
138 | 111 | builder.Services.AddJwt(); |
139 | 112 |
|
|
143 | 116 |
|
144 | 117 | app.UseMiddleware<ErrorHandlingMiddleware>(); |
145 | 118 |
|
146 | | -app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); |
| 119 | +app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); |
147 | 120 |
|
148 | 121 | app.UseAuthentication(); |
149 | 122 | app.UseMvc(); |
|
0 commit comments