Add conditional compilation for framework-specific code
Introduce framework-specific handling in `Static.cs` to support both NET and NETFRAMEWORK. Implement lazy initialization for service collection and provider, ensuring proper access and error handling.
This commit is contained in:
parent
05568b1551
commit
7689005a14
29
DigitalData.Core.Infrastructure/Static.cs
Normal file
29
DigitalData.Core.Infrastructure/Static.cs
Normal file
@ -0,0 +1,29 @@
|
||||
#if NETFRAMEWORK
|
||||
using System;
|
||||
#endif
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure
|
||||
#if NET
|
||||
;
|
||||
#elif NETFRAMEWORK
|
||||
{
|
||||
#endif
|
||||
|
||||
public class Static
|
||||
{
|
||||
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
||||
|
||||
public static IServiceCollection Services => LazyProvider.IsValueCreated
|
||||
? LazyServices.Value
|
||||
: throw new InvalidOperationException("Service collection is not available after the service provider has been built.");
|
||||
|
||||
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
||||
|
||||
public static IServiceProvider Provider => LazyProvider.Value;
|
||||
}
|
||||
|
||||
#if NETFRAMEWORK
|
||||
}
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user