feat(Client): Hinzufügen einer statischen Eigenschaft zur Konfiguration von Optionen in lokalen
This commit is contained in:
parent
2fbd50d52e
commit
816b72bfc8
@ -9,13 +9,31 @@ namespace Leanetec.EConnect.Client;
|
||||
/// </summary>
|
||||
public static class Client
|
||||
{
|
||||
private static Action<ClientOptions>? _options = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration options for the EConnect client.
|
||||
/// Can only be set once; subsequent attempts to set will result in an exception.
|
||||
/// </summary>
|
||||
public static Action<ClientOptions> Options
|
||||
{
|
||||
get => _options ?? throw new InvalidOperationException("EConnect Client options have not been configured. Please set the 'Client.Options' property before accessing client services.");
|
||||
set
|
||||
{
|
||||
if (_options is null)
|
||||
_options = value;
|
||||
else
|
||||
throw new InvalidOperationException("EConnect Client options have already been configured. Reassignment is not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lazily initializes the <see cref="IServiceProvider"/> that registers and builds the EConnect client services.
|
||||
/// </summary>
|
||||
private static readonly Lazy<IServiceProvider> _serviceProvider = new(() =>
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddEConnectClient();
|
||||
services.AddEConnectClient(Options);
|
||||
return services.BuildServiceProvider();
|
||||
});
|
||||
|
||||
|
||||
@ -4,9 +4,8 @@ namespace Leanetec.EConnect.Client;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddEConnectClient(this IServiceCollection services, Action<ClientOptions>? clientOptions = null)
|
||||
public static IServiceCollection AddEConnectClient(this IServiceCollection services, Action<ClientOptions> clientOptions)
|
||||
{
|
||||
clientOptions ??= _ => { };
|
||||
services.Configure(clientOptions);
|
||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));
|
||||
return services;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user