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

View 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