0

Im currently creating a middle tier layer for editing rules for an application. The data access is handled using entity framework and a repository class. My manager has suggested to inject the connection string for the database down to the repository class and I'm confused as to his thinking behind this?

Is there any need for this and what benefits would it provide?

Thanks

1 Answer 1

1

Dependency injection gives you freedom of changing the string when for example unit testing. In your case, I believe you would be better of mocking the database instead, but if you have a test database that is to be used instead of a mock, that lets you change a connection string when instanciating the object.

Sign up to request clarification or add additional context in comments.

2 Comments

Isnt the purpose of it being stored in the App-Config so it can be changed easily?
Sure, if you have another solution configuration that is complete. But if you have a set of tests that are to test your services using an in-memory database, then it would make sense.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.