Skip to content

Commit 6b0d912

Browse files
committed
Use lambda/factory version of AddSingleton
This allows the service provider to correctly dispose of our cache stacks when the application is terminated. Fixes #187
1 parent 002bc05 commit 6b0d912

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/CacheTower/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class ServiceCollectionExtensions
1717
/// <param name="cleanupFrequency">The frequency at which cache stack cleanup will be performed.</param>
1818
public static void AddCacheStack(this IServiceCollection services, ICacheLayer[] layers, TimeSpan cleanupFrequency)
1919
{
20-
services.AddSingleton<ICacheStack>(new CacheStack(layers, new[] { new AutoCleanupExtension(cleanupFrequency) }));
20+
services.AddSingleton<ICacheStack>(sp => new CacheStack(layers, new[] { new AutoCleanupExtension(cleanupFrequency) }));
2121
}
2222

2323
/// <summary>
@@ -28,7 +28,7 @@ public static void AddCacheStack(this IServiceCollection services, ICacheLayer[]
2828
/// <param name="extensions">The cache extensions to use.</param>
2929
public static void AddCacheStack(this IServiceCollection services, ICacheLayer[] layers, ICacheExtension[] extensions)
3030
{
31-
services.AddSingleton<ICacheStack>(new CacheStack(layers, extensions));
31+
services.AddSingleton<ICacheStack>(sp => new CacheStack(layers, extensions));
3232
}
3333

3434
/// <summary>

0 commit comments

Comments
 (0)