feat(Client): Hinzufügen einer statischen Eigenschaft zur Konfiguration von Optionen in lokalen
This commit is contained in:
@@ -9,13 +9,31 @@ namespace Leanetec.EConnect.Client;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Client
|
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>
|
/// <summary>
|
||||||
/// Lazily initializes the <see cref="IServiceProvider"/> that registers and builds the EConnect client services.
|
/// Lazily initializes the <see cref="IServiceProvider"/> that registers and builds the EConnect client services.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly Lazy<IServiceProvider> _serviceProvider = new(() =>
|
private static readonly Lazy<IServiceProvider> _serviceProvider = new(() =>
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddEConnectClient();
|
services.AddEConnectClient(Options);
|
||||||
return services.BuildServiceProvider();
|
return services.BuildServiceProvider();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ namespace Leanetec.EConnect.Client;
|
|||||||
|
|
||||||
public static class DependencyInjection
|
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.Configure(clientOptions);
|
||||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));
|
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));
|
||||||
return services;
|
return services;
|
||||||
|
|||||||
Reference in New Issue
Block a user