Suppose that we have three layers; UI, Business, Data. We are using DI. I don't wan't Data layer to be accessible from UI.
The problem is about DI registration of Data layer. Composition root is in UI and I don't wan't to have any reference to Data there. I've found this answer. As I understand, we should reference to all layers and think they are libraries not layers. This way I can specify that my Business layer use Data layer or anything else that I want. After all this is why DI is around.
It's correct, but there is a problem! We shouldn't use Data layer at UI. But once a developer accidentally referenced from UI to Data, and another one injected something from Data layer to a UI class directly. So he skipped the Business layer that I never want.
How can I handle such situations? I'd like to have some limitations, but on the other hand I want the DI flexibility.
Of course some folks believe that we can have a separate library just for dependency registration.
What is the best pattern here?