EventStore / EventStore-Client-Dotnet

Dotnet Client SDK for the Event Store gRPC Client API written in C#
Other
138 stars 38 forks source link

All settings classes like `EventStoreClientConnectivitySettings` must be records to be equatable out of the box #272

Open xperiandri opened 8 months ago

xperiandri commented 8 months ago

Is your feature request related to a problem? Please describe. I have several environments within the same app (default and sandbox). DB connections may vary for each environment. I want to add a health check only if database addresses are different. I want to compare EventStoreClientConnectivitySettings but they are not IEquatable<EventStoreClientConnectivitySettings>

Describe the solution you'd like Just mark all settings classes as record to bring value semantics and IEquatable<> implementation out of the box

Describe alternatives you've considered Implement IEqualityComparer for each of the settings class

alexeyzimarev commented 8 months ago

Don't you use the connection string? It's the easiest way to configure ESDB client in .NET using ASP.NET Core configuration framework, as well as compare the settings.

xperiandri commented 8 months ago

A connection string may be different while connecting to the same database. And the connection target will not change frrom that

ylorph commented 8 months ago

Why / When do you need to compare and change the connectivity settings ? Most of the time I'm very explicit about those and do not let the code change those on the fly . I.e. something like the following :

{
    "ConnectionStrings": {
        "default": "esdb+discover://default_cluster_address:2113",
        "sandbox": "esdb+discover://sandbox_cluster_address:2113"
    }
}
using EventStore.Client;
using Microsoft.Extensions.Configuration;

IConfiguration configuration =new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

var connections =new  Connections(configuration);

Console.WriteLine(connections.Default.ConnectionName);
Console.WriteLine(connections.Default_Follower.ConnectionName);
Console.WriteLine(connections.Sandbox.ConnectionName);

public class Connections {
    public Connections(IConfiguration c) {
        var settings = EventStoreClientSettings.Create(c.GetConnectionString("default")!);
        settings.ConnectionName = "default";
        Default = new EventStoreClient(settings);

        settings = EventStoreClientSettings.Create(c.GetConnectionString("default")!);
        settings.ConnectionName = "default_follower";
        settings.ConnectivitySettings.NodePreference = NodePreference.Follower;
        Default_Follower = new EventStoreClient(settings);

        settings = EventStoreClientSettings.Create(c.GetConnectionString("sandbox")!);
        settings.ConnectionName = "sandbox";
        Sandbox = new EventStoreClient(settings);
    }

    public EventStoreClient Default { get; }
    public EventStoreClient Default_Follower { get; } 
    public EventStoreClient Sandbox { get; }
}