From 10184760d646ee418d0b428fed59905e9a9eb4c3 Mon Sep 17 00:00:00 2001 From: bounav Date: Mon, 16 Dec 2024 11:20:23 +0000 Subject: [PATCH] No longer leaking memory - DefaultSyntaxProvider and DefaultBindingProver should not be registered as singleton services --- .../Extensions/ServiceCollectionExtensions.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Spark.AspNetCore.Mvc/Extensions/ServiceCollectionExtensions.cs b/src/Spark.AspNetCore.Mvc/Extensions/ServiceCollectionExtensions.cs index 034d8aa0..837e06d0 100644 --- a/src/Spark.AspNetCore.Mvc/Extensions/ServiceCollectionExtensions.cs +++ b/src/Spark.AspNetCore.Mvc/Extensions/ServiceCollectionExtensions.cs @@ -34,37 +34,37 @@ public static IServiceCollection AddSpark(this IServiceCollection services, Acti services.Configure(setupAction); } - // TODO: Reduce memory consumption cause by loading the assembly of the views compiled dynamically services - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton(); + .AddScoped() + .AddScoped() + .AddScoped() + .AddScoped(); services - .AddSingleton() - .AddSingleton() + .AddScoped() + .AddScoped() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddScoped() .AddSingleton(f => f.GetService().CreateDefaultViewFolder()) .AddSingleton() .AddSingleton() .AddSingleton(); - services.AddSingleton(c => null); + services + .AddSingleton(f => null); services .AddSingleton(); services - .AddSingleton(); + .AddScoped(); services .AddTransient, SparkMvcOptionsSetup>() .AddTransient, SparkMvcViewOptionsSetup>() - .AddSingleton(); + .AddScoped(); return services; }