Developer 02 7689005a14 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.
2025-09-30 19:48:00 +02:00

29 lines
794 B
C#

#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