Reading Lists From Appsettings.json - BitScry
Maybe your like
Published by Shinigami on 14 November 2017
About this site
This is a blog to help me remember some of the coding challenges I’ve faced and hopefully help others out if they’re suffering the same problems.
Recent Posts
- Installing TrueNAS on TerraMaster F4-425
- Proxmox LXC Containers Fail to Start After Reboot
- Adding a Sonoff Zigbee Dongle Plus P Router to Zigbee2MQTT
- Configuring Raspberry Pi 5 with NVME Hat
- Pass Through an iGPU to Frigate from Proxmox
Tag Cloud
.NET .NET Core AAD API appsettings.json ASP.NET Core Authentication Authorization Azure Azure Active Directory Azure Function Azure Storage Blob Bootstrap C# Cloud Storage Console Application CSS CSV DataTable Dependency Injection Dictionary Docker Entity Framework Enum Extension HTML Image JavaScript jQuery JSON List MVC Newtonsoft Raspberry Pi RestSharp Serilog SQL Stored Procedure Stream Table Table Storage Web App Web Application WordPress
SearchSearchCopyright
Any code within Reading Lists from appsettings.json by Shinigami is licensed under a Creative Commons Attribution 4.0 International License. I’ve been using the SendGrid API for a project and I was trying to be lazy and read multiple email addresses to send to from a single parameter in appsettings.json with the email addresses separated by a semicolon. Strangely this only sends to the first email in the string so I needed to do a little more work and store the emails in an array in appsettings.json and to read this into a list and then loop through it adding each address individually.
{ "Email": { "ToEmails": [ "[email protected]", "[email protected]", "[email protected]" ] } } // Build configuration IConfigurationRoot _config = new ConfigurationBuilder() .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) .AddJsonFile("appsettings.json", false) .Build(); List<string> emailTo = _config.GetSection("Email:ToEmails").Get<List<string>>(); foreach(string email in emailTo) { sendGridMessage.AddTo(newEmailAddress(email)); }If you are aiming to use this in a console application then you’ll need to install the following NuGet packages.
Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.Binder Categories: Programming Tags: appsettings.jsonArrayListSendGridSettings1 Comment
Nayan · 21 June 2022 at 07:44
Can you help me to mock this “_config.GetSection(“Email:ToEmails”).Get<List>();” with moq for unit testing? I am having hard time to figure this out
ReplyLeave a Reply Cancel reply

Your email address will not be published. Required fields are marked *
Name * Email * Website What's on your mind?Save my name, email, and website in this browser for the next time I comment.
Related Posts
ProgrammingProxmox LXC Containers Fail to Start After Reboot
After a routine reboot of my Proxmox host (along with the network switch and router), I found that all of my VMs started fine, but none of my LXC containers would come up. Trying to Read more
ProgrammingPass Through an iGPU to Frigate from Proxmox
I am running Proxmox on a Dell Optiplex 7050 Mini with an i7-6700T. The i7-6700T has an integrated Intel 530 GPU and in order to use this GPU in Frigate for hardware acceleration it needs Read more
ProgrammingCreating a Frigate VM on Proxmox
Although there’s a community script for creating a Frigate LXC in Proxmox I’ve found it easier get working with external devices like hard drives and a Coral TPU by running as a VM rather than Read more
Tag » Appsettings.json Guid
-
Dictionary
Mapping From Appsettings.json In C# - Stack ... -
Strongly Typed Configuration Settings In ASP.NET Core Part II
-
Getting Value From Appsettings.json In .NET Core - Telerik
-
Safe Storage Of App Secrets In Development In ASP.NET Core
-
ASP.NET Core: Step By Step Guide To Access Appsettings.json In ...
-
Unable To Bind Dictionary With Int Key Type From Appsettings.json To ...
-
Dell Trusted Device Installation And Administrator Guide V4.5
-
How To Use ASP.NET Core IOptions Pattern - Referbruv
-
Custom Configuration Section (Array) In Appsettings.json - Anycodings
-
Settings | Documentation Center | ABP.IO
-
Tutorial - ASP.NET Core First Query With Couchbase SDK 3
-
Using User Secrets Configuration In .NET -.NET Core Tutorials
-
A Step By Step Guide For ASP.NET Core Configuration
-
Configure .NET Core Pull Relay Server, PS V2.0 - VMware Docs