Constructor Injection - Do we inject factories as well?

前端 未结 3 1140
一整个雨季
一整个雨季 2021-02-15 07:08

After listening to the Clean Code Talks, I came to understand that we should use factories to compose objects. So, for example, if a House has a Door a

3条回答
  •  遇见更好的自我
    2021-02-15 07:39

    If you inject too many factories that is a code smell called constructor over-injection that indicates your class is doing too much.

    Many containers provide a feature called auto-factories. That means they generate factories of type Funcautomatically if they know how to generate T.

    Castle Windsor has an advanced feature called Typed Factory facilities which generates implementations of a factory interface on-the-fly.

    There is also a port of typed factories for Unity in the TecX project.

提交回复
热议问题