lundi 2 novembre 2020

Dependency injection - problematic middle objects

I know that using dependency injection instead of for example singletons for shared resources is a good practice. Sometimes though this approach seams very messy.

Imagine my app contains a list of products which it can modify from within two screens (main screen and product-list screen). Let's say that the only way to access product-list screen is via a middle screen. In this situation I cannot pass the ProductService object directly from main screen to the product-list screen, instead I have to make a property "productService" also in the middle screen although it doesn't use it. It only passes it on to the product-list screen.

It doesn't seem very elegant to me as the only purpose of that property in the middle screen is to just pass it to another object. Do you have any better solution to this problem?

Aucun commentaire:

Enregistrer un commentaire