Singleton for Application Configuration

前端 未结 6 490
南方客
南方客 2021-02-05 02:49

In all my projects till now, I use to use singleton pattern to access Application configuration throughout the application. Lately I see lot of articles taking about not to use

6条回答
  •  遥遥无期
    2021-02-05 03:07

    Use dependency injection to inject the single configuration object into any classes that need it. This way you can use a mock configuration for testing or whatever you want... you're not explicitly going out and getting something that needs to be initialized with configuration files. With dependency injection, you are not passing the object around either.

提交回复
热议问题