Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 34663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:06:50+00:00 2026-05-10T14:06:50+00:00

A database application that I’m currently working on, stores all sorts of settings in

  • 0

A database application that I’m currently working on, stores all sorts of settings in the database. Most of those settings are there to customize certain business rules, but there’s also some other stuff in there.

The app contains objects that specifically do a certain task, e.g., a certain complicated calculation. Those non-UI objects are unit-tested, but also need access to lots of those global settings. The way we’ve implemented this right now, is by giving the objects properties that are filled by the Application Controller at runtime. When testing, we create the objects in the test and fill in values for testing (not from the database).

This works better, in any case much better than having all those objects need some global Settings object — that of course effectively makes unit testing impossible 🙂 Disadvantage can be that you sometimes need to set a dozen of properties, or that you need to let those properties ‘percolate’ into sub-objects.

So the general question is: how do you provide access to global application settings in your projects, without the need for global variables, while still being able to unit test your code? This must be a problem that’s been solved 100’s of times…

(Note: I’m not too much of an experienced programmer, as you’ll have noticed; but I love to learn! And of course, I’ve already done research into this topic, but I’m really looking for some first-hand experiences)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:06:50+00:00Added an answer on May 10, 2026 at 2:06 pm

    You could use Martin Fowlers ServiceLocator pattern. In php it could look like this:

    class ServiceLocator {   private static $soleInstance;   private $globalSettings;    public static function load($locator) {     self::$soleInstance = $locator;   }    public static function globalSettings() {     if (!isset(self::$soleInstance->globalSettings)) {       self::$soleInstance->setGlobalSettings(new GlobalSettings());     }     return self::$soleInstance->globalSettings;   } } 

    Your production code then initializes the service locator like this:

    ServiceLocator::load(new ServiceLocator()); 

    In your test-code, you insert your mock-settings like this:

    ServiceLocator s = new ServiceLocator(); s->setGlobalSettings(new MockGlobalSettings()); ServiceLocator::load(s); 

    It’s a repository for singletons that can be exchanged for testing purposes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a database application that runs on various independent servers. Each
I have an application that is database intensive. Most of the applications methods are
I'm writing a database application that connects to SQL server. I'd like to implement
In a database-centric application that is designed for multiple clients, I've always thought it
I have an application that reads a database and outputs alerts to any dependencies
I have an application that reads a table from a database. I issue an
We develop Win32 application that access to SQL 2005 database through Linq to SQL.
I have a database for a web application that is home to some personal
I have a c# application that interfaces with the database only through stored procedures.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.