I'm looking for an approach to the following problem:
I have a reusable library. It contains a controller class, in the MVC sense. Let's say it's called UserAdministrationController
, and it's for editing users. This class requires an object implementing IUserStorage
, for storing its data. The library doesn't need to know the details of how this object works.
Now I want to write an application that includes the library. In it, I'll provide an implementation of IUserStorage
. To instantiate this, I'll need to pass it some dependencies, like a database object, and other things that my application only knows about at runtime.
But how would I then pass this object from my application to the library? I'm not instantiating the UserAdministrationController
directly from my application; it gets created by the library itself.
Hope this makes sense. I'm trying to keep my description abstract and not specific to a particular framework or language.