How to inject a list of key-value entries into a Dictionary like object

26 Views Asked by At

My eventual goal is to get a dictionary object injected by Configuration..

Say I have an object in my appsettings.json file which is

  "MyDictionary": {
    "Key1": "Value1",
    "Key2": "Value2",
    "Key3": "Value3"
  }

How do I get it injected into a Dictionary object to be run in a class without using IConfiguration configuration?

public class SendGridEmailSender : IEmailSender
{
    public SendGridEmailSender(ISendGridClient sendGridClient, Dictionary<string, string> myDictionaryObj)

The difficulty is to make asp.net to work out a list objects from json for me.

If I have to use IConfiguration as an initializing parameter, what should I do in unit tests?

0

There are 0 best solutions below