Improve exception message in Static.cs
Updated the exception message in the `Static` class to clarify that services cannot be accessed after the service provider has been created. This change enhances the clarity of the error for developers.
This commit is contained in:
parent
d5a8619b4d
commit
5a3cbe8ecf
@ -17,8 +17,8 @@ public class Static
|
|||||||
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
||||||
|
|
||||||
public static IServiceCollection Services => LazyProvider.IsValueCreated
|
public static IServiceCollection Services => LazyProvider.IsValueCreated
|
||||||
? LazyServices.Value
|
? LazyServices.Value
|
||||||
: throw new InvalidOperationException("Service collection is not available after the service provider has been built.");
|
: throw new InvalidOperationException("Services cannot be accessed after the Provider has been created.");
|
||||||
|
|
||||||
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user