Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Fowler <davidfowl@gmail.com>2021-03-19 18:16:51 +0300
committerGitHub <noreply@github.com>2021-03-19 18:16:51 +0300
commit93cee2661484ebc292a56a02405f36551bbe2eaf (patch)
tree5c946301c9117bc2e6bf47b13ecec8e0f09880d1 /src/libraries
parent95f64201926c311e520dcc1ca30c45744d0e70ad (diff)
Slimmer IOptions<T> (#49852)
* Slimmer IOptions<T> - Use a Lazy instead of the IOptionsCache (which is a concurrent dictionary)
Diffstat (limited to 'src/libraries')
-rw-r--r--src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs2
-rw-r--r--src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs22
2 files changed, 23 insertions, 1 deletions
diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs
index d9ff1e75b03..cfba9735907 100644
--- a/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs
+++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs
@@ -26,7 +26,7 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(services));
}
- services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptions<>), typeof(OptionsManager<>)));
+ services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptions<>), typeof(UnnamedOptionsManager<>)));
services.TryAdd(ServiceDescriptor.Scoped(typeof(IOptionsSnapshot<>), typeof(OptionsManager<>)));
services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptionsMonitor<>), typeof(OptionsMonitor<>)));
services.TryAdd(ServiceDescriptor.Transient(typeof(IOptionsFactory<>), typeof(OptionsFactory<>)));
diff --git a/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs b/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs
new file mode 100644
index 00000000000..6920efe506e
--- /dev/null
+++ b/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Microsoft.Extensions.Options
+{
+ internal class UnnamedOptionsManager<[DynamicallyAccessedMembers(Options.DynamicallyAccessedMembers)] TOptions> :
+ IOptions<TOptions>
+ where TOptions : class
+ {
+ private readonly Lazy<TOptions> _lazy;
+
+ public UnnamedOptionsManager(IOptionsFactory<TOptions> factory)
+ {
+ _lazy = new Lazy<TOptions>(() => factory.Create(Options.DefaultName));
+ }
+
+ public TOptions Value => _lazy.Value;
+ }
+}