简体   繁体   中英

Chain of responsibility with large configs

I am using the chain of responsibility design pattern for my pipeline. One problem I discovered is that the configuration object becomes larger and larger as I add more chains. Essentially, my config object is becoming a massive singleton. Is there an effective way to handle this situation?

Details:

My current set up is

handler.next = handler2
handler2.next = handler3
...

and I use the chain by passing a config object to it.

handler.HandleRequest(config)

the config object has all the config information required for the handlers thus becomes larger and larger as I add more chains.

Possible solution:

In this post the best answer is to use dependency injection.

Which design patterns can be applied to the configuration settings problem?

However, I am not sure how to use dependency injection on the chain of responsibility design without substantially changing the design.

Could someone help me on this issue? Thanks!

I think you are trying to do things together that don't really belong together.

If you need to extract settings/configuration values for different parts of your application, why do you try to read them all in one place?

I prefer small "settings objects" for each component that needs some kind of settings. I usually start with objects that contain all hard-coded default values and derive from that base-settings when I have to. The derived objects can read from arbitrary sources (most of the time that is the app.config file but I used databases and web-services as well).

This is a blog post that describes settings objects in more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM