• About Morris Development
  • A Focus for Cloud Efficiency
    • Microsoft Azure
    • Amazon Web Services
  • What our Clients Say
  • Our Products
    • PreschoolDB
    • WebinarDB
  • Contact Us

Morris Development

Custom System Development and Integration

September 15, 2023

appsettings.json is not your friend

The most common issue we have is getting a connection string from our appsettings.json or webconfig file into a class that we will use to call the database. This is even more difficult when we start getting lots of integration systems like Amazon S3 or Google Storage. No matter what, we don’t want those secure keys in our source control, so we put the credentials into Appsettings.json. But, then you need to make sure to keep them all out of source control and make sure every damn developer you ever hire only has access to certain datasets, etc… it gets to be quite the chore.

So, for me, I keep a settings table in the database and the database connection string on the server’s appsetting. But, for usage, I keep all of that in a singleton class.

During the program’s start I pull the connection string from appsettings.json, then initialize a class I wrote called “AppSettings”, like this appset = new AppSettings(connectionString); The class itself will then pull all the setting information out of the database and populate the class properties as appropriate. Then, I register that class as a singleton.

At this point, I can inject that singleton class into any controller and all my settings will be available with no reading of files or additional calls to the database.

Moreover, I can actually SET the values dynamically if I choose. So, I can open the program and get to the part where I’d store a google file and it would say, “oh. you don’t have a credentials for that. Type them in here in this nice form”, which will populate the database table AND set the values in the AppSettings singleton class in real time without rebooting the program.

This is great, except sometimes you just want to “get the data”. So, suppose you had a class called “MyAmazonS3” and you have your credentials in AppSettings.AWS. I would set it up like this: new MyAmazonS3(AppSettings.AWS) and then register THAT as a singleton as well. So you can use the same class with the credentials filled out wherever you’d like simply by injecting it into the controller.

Whether you choose to make your classes singletons or simply make new ones and pass in the credentials, I think this is better than keeping all your credentials in a text file.

Article by MacGyver / Angular 2

About MacGyver

I've worked with database systems for over 20 years, and started my own company in 2000. Almost all my business consists of internal database systems, either ERP or CRM. My programming is primarily in Angular / Microsoft C# and MS SQL.

About This Site

Morris Development has been specializing in internal database system design and integration since 1999. We provide long-term management and support of secure data systems for many businesses as well as developing the more complex code structures for ERP systems like Intellievent, Apidas, and AVMS.

This site is primarily for our developers to keep track up various technologies and updates that are used by Morris Development.

Training

Integrating Angular Microsite with .Net

Private Data Caching with Google Storage

Continuous Deployment for Production Releases?

Azure Websites – the perfect Angular host

Angular 2

  • Angular 2 Authentication
  • Angular Command Line Interface
  • Material Design for Angular
  • Using Observables in Angular 2

Mentors

  • Ben Nadel
  • Dan Wahlin
  • Deborah Kurata
  • John Papa

Staff

  • Dan Morris

Training

  • Google Development Courses
  • Microsoft Virtual Academy
  • PluralSight
  • Test Deep Links

© 2025 · Morris Development