From 7689005a14b4a1b4b51346a0e0c2e839dbbcce72 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 30 Sep 2025 19:48:00 +0200 Subject: [PATCH] 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. --- DigitalData.Core.Infrastructure/Static.cs | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 DigitalData.Core.Infrastructure/Static.cs diff --git a/DigitalData.Core.Infrastructure/Static.cs b/DigitalData.Core.Infrastructure/Static.cs new file mode 100644 index 0000000..5348a14 --- /dev/null +++ b/DigitalData.Core.Infrastructure/Static.cs @@ -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 LazyServices = new Lazy(() => 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 LazyProvider = new Lazy(Services.BuildServiceProvider); + + public static IServiceProvider Provider => LazyProvider.Value; +} + +#if NETFRAMEWORK + } +#endif \ No newline at end of file