getbrevo / brevo-csharp

MIT License
4 stars 2 forks source link

Concurrency of key #2

Open AssCasc opened 8 months ago

AssCasc commented 8 months ago

According to the getting started, api-key and pertner-key must be stored in "Configuration.Default.ApiKey" dictionary; in this way the kays are shared to all library. In my case i need use the library in large shared service with hundreds of Brevo connections. You will understand that I cannot use shared keys throughout the library but each connection requires its own keys. I need something like that:

using System;
using System.Diagnostics;
using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;

namespace Example
{
    public class Example
    {
        public void main()
        {

              var apiInstance = new AccountApi(api-key, partner-key);

            try
            {
                // Get your account information, plan and credits details
                GetAccount result = apiInstance.GetAccount();
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling AccountApi.GetAccount: " + e.Message );
            }

        }
    }
}

Is this possible? Or if i fork the project you will accept the update?

PatrickKunz commented 3 months ago

Please merge the pull request. Singletons are not a good solution in multithreaded applications, especially when they offer direct write access to a list.

AssCasc commented 2 months ago

Sorry i forgot to write in this thread but after doing all the conversion work i realized that it is possible to use:

Dim brevoConfig As New Configuration()
brevoConfig.ApiKey.Add("api-key", your-api-key)
Dim apiInstance As New AccountApi(brevoConfig)

to set the api key specifically for this invocation

PatrickKunz commented 2 months ago

Thanks for the information. Didn't notice that :) The examples should also use this instead of the singleton.