Say I have an interface CrawlerInterface
with implementation PageCrawler
and FeedCrawler
; if we happen to need both classes in a controller, how can that be achieved with constructor injection?
Previously we use a central ServiceProvider
to register (i.e. App::bind
) such classes, but in most cases we only have 1 implementation of an interface, so said problem hasn't occured to us yet.
PS: I also wonder if this problem suggests we should split the controller.
Updates:
Thanks for the comments and response, to explain, said interface has only one public method: crawl($uri)
, and both page/feed crawler implements it as given a resource identifier, return resource.
My follow up question:
Say we are in a calculator
scenario where Addition, Subtraction and Multiplication share the same interface Operation
, which has only 1 public method run
, at some point we will still encounter this problem right? How do we handle situation like these in general with ServiceProvider
?