feat(Client): statische Klasse zur Behandlung des Standarddienstanbieters mit „Lazy Loading“ erstellt
This commit is contained in:
parent
2c73022526
commit
3377cc6121
31
src/Leanetec.EConnect.Client/Client.cs
Normal file
31
src/Leanetec.EConnect.Client/Client.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Leanetec.EConnect.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a lazily initialized <see cref="IServiceProvider"/> for accessing the EConnect client services,
|
||||
/// including an <see cref="IMediator"/> instance for sending and publishing messages.
|
||||
/// </summary>
|
||||
public static class Client
|
||||
{
|
||||
/// <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();
|
||||
return services.BuildServiceProvider();
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initialized <see cref="IServiceProvider"/> that provides access to registered EConnect client services.
|
||||
/// </summary>
|
||||
public static IServiceProvider Provider => _serviceProvider.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMediator"/> instance used for sending commands, queries, and publishing events within the EConnect client.
|
||||
/// </summary>
|
||||
public static IMediator Mediator => Provider.GetRequiredService<IMediator>();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user