passing DB Connection object to methods

前端 未结 9 1763
抹茶落季
抹茶落季 2020-12-25 13:29

Was wondering if it is recomended to pass a database connection object around(to other modules) or let the method (in the other module) take care of setting it up. I am lea

9条回答
  •  佛祖请我去吃肉
    2020-12-25 14:10

    For automated testing purposes, it's usually easier to pass it in. This is called dependency injection.

    When you need to write tests, you can create a mock database connection object and pass that instead of the real one. That way, your automated tests won't rely on an actual database that needs to be repopulated with data every time.

提交回复
热议问题