Created
November 12, 2020 15:30
-
-
Save screamingworld/c58e628afe6425b08745a53a91ebb617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
} | |
} | |
} |
Good!
Good
So if you are interested... This is only a snippet from my tutorial...
https://markusherkommer.medium.com/using-net-angular-kubernetes-azure-devops-terraform-eventhubs-and-other-azure-resources-bbeb0324a688
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good