How can I bind a singleton that implements multipl...
# kodein
r
How can I bind a singleton that implements multiple interfaces into multiple sets? So, imagine a declaration
FooBar: Foo, Bar
. Instead of:
Copy code
inBindSet<Foo> {
  bind { singleton { new(::FooBar) } }
}

inBindSet<Bar> {
  bind { singleton { new(::FooBar) } }
}
which seems like it will create two singletons, and even if it doesn't, it isn't very clearly expressing intent. I should be able to do:
Copy code
bind { singleton { new(::FooBar) } }

inBindSet<Foo> {
  add { instance<FooBar>() }
}

inBindSet<Bar> {
  add { instance<FooBar>() }
}
but I can't figure out the syntax.
r
The actual syntax is
Copy code
bind { singleton { Cls() } }

            bindSet<Itf> {
                add { singleton { instance<Cls>() } }
            }
            bindSet<Itf2> {
                add { singleton { instance<Cls>() } }
            }
here is the documentation https://kosi-libs.org/kodein/7.19/core/multi-binding.html
👍 1
😮 1