fix: Projektdateiname für DigitalData.Core.Legacy.Client korrigiert
This commit is contained in:
26
DigitalData.Core.Legacy.Client/ServiceFactory.cs
Normal file
26
DigitalData.Core.Legacy.Client/ServiceFactory.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
namespace DigitalData.Core.Legacy.Client
|
||||
{
|
||||
public static class ServiceFactory
|
||||
{
|
||||
private static readonly IServiceCollection _services = new ServiceCollection();
|
||||
private static readonly Lazy<IServiceProvider> _lazyProvider = new Lazy<IServiceProvider>(Build);
|
||||
|
||||
public static IServiceCollection Services => !_lazyProvider.IsValueCreated
|
||||
? _services
|
||||
: throw new InvalidOperationException(
|
||||
"Service provider has already been created. " +
|
||||
"Further modifications to the service collection are not allowed. " +
|
||||
"This is to ensure that the dependency injection container remains in a consistent state.");
|
||||
|
||||
private static IServiceProvider Build() => _services.BuildServiceProvider();
|
||||
|
||||
public static T Provide<T>() => _lazyProvider.Value.GetRequiredService<T>();
|
||||
|
||||
public static HttpClientService<TOptions> ProvideHttpClientService<TOptions>()
|
||||
where TOptions : HttpClientOptions
|
||||
=> _lazyProvider.Value.GetRequiredService<HttpClientService<TOptions>>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user