Question

My application uses a DI framework and follows "program to an interface" practice wherever necessary.

I use constructor injection since I'd like to see the dependencies explicitly. But now the constructors of my form classes take too many parameters (>=4 e.g).

Question: Since UI design doesn't usually adhere to SRP, a Winform class might have n constructor dependencies. Do you like to leave them as they are, pass a proxy object instead, use a service locator...? Also do you inject "aspects" (logger, etc) in every constructor, given that no aop-framework is used?

Was it helpful?

Solution

There's no reason why UI implementations should not adhere to SRP. Using patterns such as MVP, MVC or MVVM, a UI class' single responsibility is to to render and collect data through the UI. This is often best done through rather passive data structures such as View Models.

The issue about constructor over-injection should be addressed by refactoring to Aggregate Services.

Aspects are best addressed through application of the Decorator design pattern.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top