2

I'm completely new to dependency injection here.

If I were building say a twitter client using dependency injection, where should the logic that controls refreshing my stream at a specific interval (say 5 minutes) be housed?

podnov
  • 115
  • 1
  • 7

1 Answers1

3

When you choose to use Dependency Injection, you choose to define abstractions that hide away implementation details. One of the biggest challenges is to forget about the implementation details while designing the abstractions.

While you may know that you'll be polling an HTTP service regularly, you shouldn't necessarily define your abstractions based on that assumption.

Imagine that things are very much different - for example that the service in question could push updates to the client. Would the abstraction still hold?

  • If you build the abstraction around the assumption that the client is a Polling Consumer, it may not fit well if you'd need to implement it on an Event-Driven Consumer instead.
  • Interestingly enough, it's easier to simulate an Event-Driven Consumer with poll-based technology.

Even if you never expect to use anything else than a Polling Consumer, the above is still a good exercise to do, because it forces you to consider whether or not you've designed a leaky abstraction.

So, to answer the question: the refresh logic belongs in the data access implementation.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736