Yaml Array Object as Environment Variable in Asp.Net Core 5

Viewed 826

Good Day

Do you know how is it possible to get an array of objects in a environment variable with yaml?

I want to get this structure:

public class WarningContacts {
   
    public List<Contact> Contacts { get; set; }

}

public class Contact {

    public String Name { get; set; }

    public String Email { get; set; }
  }

Now, in Json i do this:

  "WarningContacts": {
    "Contacts": [
      {
        "Name": "Hans Peter",
        "Email": "random@email.com"
      },
      {
        "Name": "Hans Peter2",
        "Email": "random@email2.com"
      }
    ]
  }

And it works fine when i get this configuration with C# in Asp.Net Core 5

services.Configure<WarningContacts>(Configuration.GetSection("WarningContacts"));

However, i need to do this with environment variables in yaml which would override the json configuration when it's deployed. The deployment works and other environment variables are already overwritten, so that isn't the problem.

But i just can't bring the array of objects to work with yaml files, atleast i haven't found how.

My current version would be this:

       env:
            - name: WarningContacts__Contacts__0__Name
              value: 'Hans Peter'
            - name: WarningContacts__Contacts__0__Email
              value: 'random@email.com'
            - name: WarningContacts__Contacts__1__Name
              value: 'Hans Peter2'
            - name: WarningContacts__Contacts__1__Email
              value: 'random@email2.com'

Does anybody know how to have an array of objects in a yaml file for an environment variable? Thanks for your time.

0 Answers
Related