You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Essentially a class that implements two interfaces, where only one interface may be needed elsewhere at a given time (for instance, many classes may need to read the files but only a few may need to write to them).
The FileHandler class could be instantiated as a Singleton, which in turn makes it reasonable that both FileReader and FileWriter bind to the same object. As is mentioned in #181, the following does not work (it creates two instances of FileHandler):
I've managed to solve this on my end by adding a bind_several function to the Binder class. I don't know if it covers all use cases of how injector can be used, but it does cover mine, and allows me to bind multiple interfaces to one implementation (and one instance of that implementation if the request_scope is singleton). It basically uses the same functionality as the Module classes do, just wrapped into a function.
Someone more experienced with this library could potentially point out if this is a good addition to this repository, if it requires some modification, or if it doesn't belong here at all. Regardless, the problem is solved on my end. :)
Hi!
This issue is somewhat related to #181. Let's say I have the following code structure:
Essentially a class that implements two interfaces, where only one interface may be needed elsewhere at a given time (for instance, many classes may need to read the files but only a few may need to write to them).
The
FileHandler
class could be instantiated as a Singleton, which in turn makes it reasonable that bothFileReader
andFileWriter
bind to the same object. As is mentioned in #181, the following does not work (it creates two instances ofFileHandler
):Instead, it is suggested to create a
Module
doing the following:This seems like a lot of code for a binding of several interfaces to one instance. In other DI frameworks, I've seen syntax similar to:
I don't know if I've missed something, but is this possible to do in
injector
? If not, I think it would be a nice addition to the library.Thanks!
The text was updated successfully, but these errors were encountered: