using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Newtonsoft.Json.Converters; | |
using Notifier.Common.Extensions; | |
using Notifier.Common.Settings; | |
using Notifier.WebApi.Common.Data; | |
using Notifier.WebApi.Common.Data.Entities; | |
using Notifier.WebApi.Services; | |
namespace Notifier.WebApi | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration, IWebHostEnvironment env) | |
{ | |
Configuration = configuration; | |
Environment = env; | |
} | |
public IConfiguration Configuration { get; } | |
public IWebHostEnvironment Environment { get; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services | |
.AddControllers( | |
options => | |
{ | |
// Needed because of using newtonsoft json | |
// (else there are performance issues in .net core 3) | |
options.SuppressOutputFormatterBuffering = true; | |
}) | |
.AddNewtonsoftJson( | |
options => | |
{ | |
options.UseCamelCasing(true); | |
options.SerializerSettings.Converters.Add(new StringEnumConverter()); | |
}); | |
// Configure the settings to be part of "di" via IOptions<T> | |
services | |
.Configure<AzureTableSettings>(Configuration.GetSection(nameof(AzureTableSettings))) | |
.Configure<EventHubSettings>(Configuration.GetSection(nameof(EventHubSettings))); | |
// Add application insights. | |
services.AddApplicationInsights(Configuration); | |
// Add the the needed service registrations | |
services.AddSingleton<IRepository<NotificationEntity>, StorageTableRepository<NotificationEntity>>(); | |
services.AddSingleton<INotificationService, NotificationService>(); | |
services.AddMvcCore(); | |
services.AddCors(options => | |
{ | |
options.AddDefaultPolicy(cors => | |
{ | |
cors | |
.WithOrigins(Configuration.GetSection(nameof(CorsSettings)).Get<CorsSettings>().AllowedOrigins) | |
.AllowAnyHeader() | |
.AllowAnyMethod() | |
.AllowCredentials(); | |
}); | |
}); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseCors(); | |
if (env.IsDevelopment()) | |
app.UseDeveloperExceptionPage(); | |
else | |
app.UseHsts(); | |
app.UseHttpsRedirection(); | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
} | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
Good! |
This comment has been minimized.
This comment has been minimized.
So if you are interested... This is only a snippet from my tutorial... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Good