I'm currently just starting to implement Dependency injection so i can start testing my code and have come across an issue many of times that i cant figure out.
My current case scenario:
I have a single class ( foo.cs ) that is active the whole time a windows service is running. Its responsible for polling the db for new messages then sending them out and update the db to reflect the success of the send.
My issue is that foo.cs has a dependency for the data access (Message Repository - a linq-to-sql data context) so its injected via the constructor and its life time scope is the same as foo. Everywhere I'm reading it says that a data context lifetime should be a single unit of work. So its like i need to inject the actual type i want to use and constructed it every time i want to do a single unit of work in foo rather than passing in a already constructed Repository that stays alive for the entire duration of the service.