AppSettings

2 недели назад
Hello everyone,
I am currently working on a payment plugin and would like to store the credentials from our payment gateway in the appsettings.json file. In previous version of Nop (4.50) I created a config class that implements the IConfig interface from Nop.Core.Configuration. However, doing doing the same in version 4.60 throws an error that the given key does not exist in the dictionary.


var appSettings = Singleton<AppSettings>.Instance;

var paymentGateway= appSettings.Get<PayitConfig>();

var secretKey = appSettings.Get<PayitConfig>().SecretKey;


In the above code, PayItConfig is a class that implements IConfig.
The error I am getting


User
System.Collections.Generic.KeyNotFoundException: The given key 'Ccl.Plugin.Payments.Payit.Configuration.PayitConfig' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Nop.Core.Configuration.AppSettings.Get[TConfig]() in C:\Users\jcowo\source\repos\ClearCommerce-Limited\nopCommerce_4.60.4_Source\src\Libraries\Nop.Core\Configuration\AppSettings.cs:line 51

I have already tried to search for a solution in GitHub and the forums to no avail. I've also went over the docs many times and couldn't find anything. I also added the credentials to my appsettings.json file

  "PayitConfig": {
    "Login": "superSecretLogin",
    "SecretKey": "SuperSecretKey"
  },

TIA
2 недели назад
https://www.nopcommerce.com/en/boards/topic/98833/appsettings-setup-issue
2 недели назад
Thank you! The error still appears.
2 недели назад
I'm curious, so I will ask the same that I did in that other post...
One consideration is, where are you using these "variables"?  Are they needed as part of the Startup process?  If not, consider using Settings (in the DB).

2 недели назад
Yes I have. That’s the route I’ll have to take. But I’d like to figure it out because it shouldn’t be throwing the error. During runtime, when I debug the app settings instance, I can see the values from the app settings.json and my credentials are there.