Skip to content

Instantly share code, notes, and snippets.

@screamingworld
Created November 12, 2020 15:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save screamingworld/c58e628afe6425b08745a53a91ebb617 to your computer and use it in GitHub Desktop.
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();
});
}
}
}
@shenssy
Copy link

shenssy commented Nov 12, 2020

Good

@shenssy
Copy link

shenssy commented Nov 12, 2020

Good!

@screamingworld
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment