diff --git a/Childrens-Social-Care-CPD/Program.cs b/Childrens-Social-Care-CPD/Program.cs index 4becf642..9c393073 100644 --- a/Childrens-Social-Care-CPD/Program.cs +++ b/Childrens-Social-Care-CPD/Program.cs @@ -1,12 +1,21 @@ using Childrens_Social_Care_CPD; using Childrens_Social_Care_CPD.Configuration.Features; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; var builder = WebApplication.CreateBuilder(args); + +var sw = new Stopwatch(); +sw.Start(); + builder.AddDependencies(); -await builder.AddFeatures(); +Console.WriteLine($"After AddDependencies {sw.ElapsedMilliseconds}ms"); + +await builder.AddFeatures(sw); +Console.WriteLine($"After AddFeatures {sw.ElapsedMilliseconds}ms"); var app = builder.Build(); +Console.WriteLine($"After Application Build {sw.ElapsedMilliseconds}ms"); // Ensure the features are fetched before starting the app var updater = app.Services.GetService(); @@ -14,19 +23,36 @@ { await updater.UpdateFeaturesAsync(cts.Token); } +Console.WriteLine($"After UpdateFeaturesAsync {sw.ElapsedMilliseconds}ms"); app.UseResponseCompression(); +Console.WriteLine($"After UseResponseCompression {sw.ElapsedMilliseconds}ms"); + app.UseExceptionHandler("/error/error"); +Console.WriteLine($"After UseExceptionHandler {sw.ElapsedMilliseconds}ms"); + app.UseStatusCodePagesWithReExecute("/error/{0}"); +Console.WriteLine($"After UseStatusCodePagesWithReExecute{sw.ElapsedMilliseconds}ms"); + app.UseStaticFiles(); +Console.WriteLine($"After UseStaticFiles {sw.ElapsedMilliseconds}ms"); + app.UseRouting(); +Console.WriteLine($"After UseRouting {sw.ElapsedMilliseconds}ms"); + app.UseAuthorization(); +Console.WriteLine($"After UseAuthorization {sw.ElapsedMilliseconds}ms"); + app.MapControllerRoute( name: "default", pattern: "{controller=Content}/{action=Index}"); +Console.WriteLine($"After MapControllerRoute {sw.ElapsedMilliseconds}ms"); + app.MapHealthChecks("application/status"); +Console.WriteLine($"After MapHealthChecks {sw.ElapsedMilliseconds}ms"); app.Run(); +Console.WriteLine($"After Application Run {sw.ElapsedMilliseconds}ms"); [ExcludeFromCodeCoverage] public partial class Program diff --git a/Childrens-Social-Care-CPD/WebApplicationBuilderExtensions.cs b/Childrens-Social-Care-CPD/WebApplicationBuilderExtensions.cs index 9277db36..b4157547 100644 --- a/Childrens-Social-Care-CPD/WebApplicationBuilderExtensions.cs +++ b/Childrens-Social-Care-CPD/WebApplicationBuilderExtensions.cs @@ -95,11 +95,9 @@ private static void AddSearch(IServiceCollection services) services.AddScoped(); } - public static async Task AddFeatures(this WebApplicationBuilder builder) + public static async Task AddFeatures(this WebApplicationBuilder builder, Stopwatch sw) { ArgumentNullException.ThrowIfNull(builder); - var sw = new Stopwatch(); - sw.Start(); builder.Configuration.AddUserSecrets(); Console.WriteLine($"After AddUserSecrets: {sw.ElapsedMilliseconds}ms"); @@ -125,7 +123,7 @@ public static async Task AddFeatures(this WebApplicationBuilder builder) AddHealthChecks(builder.Services); Console.WriteLine($"After AddHealthChecks: {sw.ElapsedMilliseconds}ms"); - await AddDataProtection(builder.Services, applicationConfiguration); + await AddDataProtection(builder.Services, applicationConfiguration, sw); Console.WriteLine($"After AddDataProtection: {sw.ElapsedMilliseconds}ms"); } @@ -178,7 +176,7 @@ private static void AddHealthChecks(IServiceCollection services) #pragma warning restore CA1861 // Avoid constant arrays as arguments } - private static async Task AddDataProtection(IServiceCollection services, ApplicationConfiguration applicationConfiguration) + private static async Task AddDataProtection(IServiceCollection services, ApplicationConfiguration applicationConfiguration, Stopwatch sw) { if (!string.IsNullOrEmpty(applicationConfiguration.AzureDataProtectionContainerName)) { @@ -187,10 +185,12 @@ private static async Task AddDataProtection(IServiceCollection services, Applica applicationConfiguration.AzureDataProtectionContainerName); var managedIdentityCredential = new ManagedIdentityCredential(clientId: applicationConfiguration.AzureManagedIdentityId); + Console.WriteLine($"After AddDataProtection:new ManagedIdentityCredential: {sw.ElapsedMilliseconds}ms"); var blobContainerUri = new Uri(url); var blobContainerClient = new BlobContainerClient(blobContainerUri, managedIdentityCredential); await blobContainerClient.CreateIfNotExistsAsync(); + Console.WriteLine($"After AddDataProtection:blobContainerClient.CreateIfNotExistsAsync: {sw.ElapsedMilliseconds}ms"); var blobUri = new Uri($"{url}/data-protection"); services