File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/libraries/Microsoft.Extensions.Options/src Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public static IServiceCollection AddOptions(this IServiceCollection services)
2626 throw new ArgumentNullException ( nameof ( services ) ) ;
2727 }
2828
29- services . TryAdd ( ServiceDescriptor . Singleton ( typeof ( IOptions < > ) , typeof ( OptionsManager < > ) ) ) ;
29+ services . TryAdd ( ServiceDescriptor . Singleton ( typeof ( IOptions < > ) , typeof ( UnnamedOptionsManager < > ) ) ) ;
3030 services . TryAdd ( ServiceDescriptor . Scoped ( typeof ( IOptionsSnapshot < > ) , typeof ( OptionsManager < > ) ) ) ;
3131 services . TryAdd ( ServiceDescriptor . Singleton ( typeof ( IOptionsMonitor < > ) , typeof ( OptionsMonitor < > ) ) ) ;
3232 services . TryAdd ( ServiceDescriptor . Transient ( typeof ( IOptionsFactory < > ) , typeof ( OptionsFactory < > ) ) ) ;
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using System ;
5+ using System . Diagnostics . CodeAnalysis ;
6+
7+ namespace Microsoft . Extensions . Options
8+ {
9+ internal class UnnamedOptionsManager < [ DynamicallyAccessedMembers ( Options . DynamicallyAccessedMembers ) ] TOptions > :
10+ IOptions < TOptions >
11+ where TOptions : class
12+ {
13+ private readonly Lazy < TOptions > _lazy ;
14+
15+ public UnnamedOptionsManager ( IOptionsFactory < TOptions > factory )
16+ {
17+ _lazy = new Lazy < TOptions > ( ( ) => factory . Create ( Options . DefaultName ) ) ;
18+ }
19+
20+ /// <summary>
21+ /// The default configured <typeparamref name="TOptions"/> instance, equivalent to Get(Options.DefaultName).
22+ /// </summary>
23+ public TOptions Value => _lazy . Value ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments