OrleansContrib / Orleans.Providers.MongoDB

A MongoDb implementation of the Orleans Providers: Membership, Storage and Reminders.
MIT License
100 stars 43 forks source link

Added config overload for UseMongoDBClient and AddMongoDBClient #114

Closed MarkusGeigerDev closed 1 year ago

MarkusGeigerDev commented 1 year ago

Problem:

When deploying a containerized application to, e.g., a Kubernetes cluster, chances are that different MongoDb settings come from different sources at deploy time. Database names might be set by the developer, network settings (like server names, ports, tls, etc) will be set by an operator or devops engineer and credentials will be pulled from a vault.

This is really hard to achieve, if everything is mangled into one big connection string.

Proposed solution:

I added overloads for the extension methods UseMongoDBClient() and AddMongoDBClient() that take a configuration delegate which gives the user access to all MongoDB connection settings individually.

This allows code like this, where different parts of the connection settings are pulled from different configuration sources:

[...]
  .UseMongoDBClient((ref MongoClientSettings settings) =>
    {
      var connectionString = config["Orleans:MongoDb:ConnectionString"];
      var db = config["Orleans:MongoDb:AuthDatabase"];
      var user = config["Orleans:MongoDb:User"];
      var pw = config["Orleans:MongoDb:Password"];

      settings = MongoClientSettings.FromConnectionString(connectionString);

      settings.Credential = MongoCredential.CreateCredential(db, user, pw);
    })
[...]

Edit (sidenote): We do follow the semver rules, don't we? I changed the version to 7.2.0 in accordance with rule 2, but of course I'm open for discussion.

wassim-k commented 1 year ago

Hi @MarkusGeigerDev have you had a chance to look at this? If you're busy atm I'd be happy to help out with completing the work, cheers.

MarkusGeigerDev commented 1 year ago

Hi! Thanks for your offer. I was sick most of last week, but will be back tomorrow morning and I will have a look at your comments! Cheers, Markus

wassim-k commented 1 year ago

I hope you're feeling better :)

SebastianStehle commented 1 year ago

I want to step out, so you can both decide.

MarkusGeigerDev commented 1 year ago

I want to step out, so you can both decide.

OK, @wassim-k, since you approved, I'll merge., @SebastianStehle thank you so much for your work and your support!