I am using dependency injection to inject an implementation of an interface. I would like to make it possible to call a method on the injected type with a parameter whose implementation is also being injected and based on an Interface.
Example:
SessionInterface
is implemented bySession_A
andSession_B
ConfigInterface
is implemented byConfig_A
andConfig_B
Session_A
should only use objects ofConfig_A
, same with_B
In the application an implementation of a session is injected (without a config). Later, an implementation of config can be injected, to use it as a parameter for the session's method run(ConfigInterface config)
In this method I'd like to make sure that the given parameter's type is the one corresponding to the session.
Should I use getClass()
, instanceof
or something else to check this?