Can I bind one singleton to two interfaces normally?
See original GitHub issueI want to do something like that:
bind(IFoo1.class).to(Foo.class).singletonInScope() bind(IFoo2.class).to(Foo.class).singletonInScope()
but in that case will be created two instances of Foo.
So are there any ways to bind Foo class to IFoo1 and IFoo2 interfaces by creating only one instance of Foo. And the other requirement - to initialize Foo.class automatically.
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Binding one class to several interfaces as singleton
With Ninject you can do this: var impl = new Impl(); container.Bind<IInt1>().ToMethod(c => impl); container.Bind<IInt2>().
Read more >How to register a service with multiple interfaces in ASP.NET ...
1. Provide an instance of the service (Singleton only) ... The simplest approach is to provide an instance of Foo when you're registering...
Read more >How to bind one implementation to multiple interfaces?
You need to bind them individually: bind(SimpleCallback.class).to(MassiveCallback.class ); bind(AnotherCallback.class).to(MassiveCallback.class);
Read more >Contexts and Dependency Injection - Quarkus
2, Value is an artifact id for a dependency identified by name acme . ... In other words, injecting a normal scoped bean...
Read more >Dependency Injection with Guice - Object Computing, Inc.
Often an application requires instances of multiple implementations of a given interface. For example, the OrderService may have need to submit orders to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Toothpick doesn’t support aliases. But in this case you can do:
Re-open if needed.
@Dimchel @morder @dimsuz, there are 2 reason why we didn’t implement it:
However, it is possible to achieve the same by doing it more explicit: using a Provider.
Then you can use it:
This sample might not be optimal, but it is to show the idea.