Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multibinding #164

Closed
wants to merge 5 commits into from
Closed

Conversation

mareklat
Copy link

@mareklat mareklat commented Feb 25, 2021

Proposal for implementation of multibinding feature.

All changes have no effect on the current implementation. Everything is controlled by the inToSet flag. If flag is set to false, the library works the same like before the changes.

Discussion #75

@escamoteur
Copy link
Collaborator

Hi, you were faster than I ecpected :-) What isn't clear to me what is the benefit of registering several instances into a set compared to just register a Set object that contains all the instances you need?

@mareklat
Copy link
Author

mareklat commented Feb 26, 2021

In a situation where I register Set with all instances I need to know them all. Every time I create a new implementation, I have to remember this place and add it to the Set.

You could use multibinding to implement a plugin architecture, where each module has no idea about each other and does not require changes in several places each time.

An example situation. We want to clear all data when logging out. The class responsible for this action (eg. LogoutCleaner) has injected Set<Cleanable> and calls the clear method on each.
Any module that wants its data to be removed when logging out just creates an object implementing Cleanable. Thanks to multibinding, all this happens automatically. You don't have to update Set manually every time.

All of this allow us to write clean code that is compilant with SRP.

@escamoteur
Copy link
Collaborator

Hmm, but wouldn't it then make sense not to have to pass a inToSet and just search registered types that fit the type?

@mareklat
Copy link
Author

mareklat commented Mar 1, 2021

The solution with inToSet flag was work around for the problem with the allowReassignment == true flag. If we didn't care about it, getting just Set would be a better solution

@escamoteur
Copy link
Collaborator

You always could use different names to register different instances.
Also on second thought wouldn't it make more sense to query all types that are equal or derived types?
in that case you could register them all with their real type and just query for the parent type

@mareklat
Copy link
Author

I guess that requires the use of a reflection, right? So collecting instances in to Set will be on runtime?

@escamoteur
Copy link
Collaborator

Not refelction, but it would require ireating over all registered objects in getit and make 'is' test.

@mareklat mareklat closed this Jun 11, 2021
@mareklat mareklat deleted the multibinding branch June 14, 2021 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants