Skip to content Skip to sidebar Skip to footer

Dependency Injections With Mutable Objects

Would it be a bad idea to pass anything that could possibly not work in the future to a class? For instance, passing a database connection (or anything that can possibly have it's

Solution 1:

A database connection is a perfect example of something to pass into a class for dependency injection.

Dependency injection is useful for testing your models/classes, and during testing you want to "mock" certain services such as your database. In your tests, instead of "injecting" a database object, you would "inject" a mock object that models your database functionality.


Post a Comment for "Dependency Injections With Mutable Objects"