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

getAll with base types possible? #8

Closed
HerrNiklasRaab opened this issue Jan 3, 2019 · 5 comments
Closed

getAll with base types possible? #8

HerrNiklasRaab opened this issue Jan 3, 2019 · 5 comments

Comments

@HerrNiklasRaab
Copy link
Contributor

Hello jonsamwell,

is it possible to implement following behaviour without reflection:

UserRepository _userRepository = Injector.getInjector().get<UserRepository>();
ChatRepository _chatRepository = Injector.getInjector().get<ChatRepository>();
PostRepository _postRepository = Injector.getInjector().get<PostRepository>();

var allRepositories = Injector.getInjector().getAll<BaseRepository>();

Every Repository is derived from BaseRepository.

Would be a nice feature :).

Niklas

@jonsamwell
Copy link
Owner

Hi @HerrNiklasRaab

I'm not sure this would be possible without the use of mirrors (which can't be used). The way I can think of getting around this at the moment would be to additionally register each repository as a named instance against the BaseRepository type.

injector.map<UserRepository>((i) => new UserRepository());
injector.map<BaseRepository>((i) => i.get<UserRepository>(), key: "UserRepository");
injector.map<ChatRepository>((i) => new ChatRepository());
injector.map<BaseRepository>((i) => i.get<ChatRepository>(), key: "ChatRepository");

var allRepositories = Injector.getInjector().getAll<BaseRepository>();

This isn't ideal so I'll investigate another solution if I get some free time this week.

@jonsamwell
Copy link
Owner

@HerrNiklasRaab did this help?

@grAPPfruit
Copy link

This definitely helped me even though I would prefer a prettier solution ;)

@HerrNiklasRaab
Copy link
Contributor Author

I am not using it actively, using it right now.

@jonsamwell
Copy link
Owner

Sorry this is just not possible without the use of mirrors.

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

No branches or pull requests

3 participants