Singleton for Application Configuration

前端 未结 6 496
南方客
南方客 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:02

    For that specific situation I would create one configuration object and pass it around to those who need it.

    Since it is the configuration it should be used only in certain parts of the app and not necessarily should be Omnipresent.

    However if you haven't had problems using them, and don't want to test it that hard, you should keep going as you did until today.

    Read the discussion about why are they considered harmful. I think most of the problems come when a lot of resources are being held by the singleton.

    For the app configuration I think it would be safe to keep it like it is.

提交回复
热议问题