Hi Thedric,
this has been one of my first ideas, but it does not work the way one
would expect. If you use Rebind(), it clears all bindings for that
service and then executes a standard Bind()-command. So if you have,
for example, the following bindings:
Bind<INavigationForm>().To<FormA>().Named("FormA");
Bind<INavigationForm>().To<FormB>().Named("FormB");
You then want to bind a different form to INavigationForm named FormB.
If you do
Rebind<INavigationForm>().To<FormBDifferent>().Named("FormB");
you will have no bindings for INavigationForm except FormBDifferent.
This ist not 100% intuitive because one might think that only the
binding which matches the arguments gets replaced.
That being said, I tried to modify Ninject2 to change the Rebind()
behavior, but it is far from trivial. To do a replace, you have to
wait until the binding command is complete, so doing it from the start
(like Rebind does) is not an option. So you'd have to add a command
like Instead() at the end of the command, but at that point you are in
the BindingBuilder where there's no way of deleting / overwriting /
altering bindings in the kernel.
So for me the only option was to modify the resolution behavior to
always resolve the latest binding added (this effects about 8 lines of
code in one class).
Surely, this may seem like a special case, but I do think that it
really is not at least in my case:
We have an application where you select one of several "wizards" -
basically use-cases with several steps. They do have a lot of
similarities, so I decided to make a hierarchy where you have an
abstract process from which all others inherit. It's basically a
module defining lots of bindings. And just like objects show
polymorphal behavior (because you can override methods, where the base
method assigns a value A to a field, and the overridinig method
replaces it with value B), I needed my bindings to be overridable (the
base method declares 20 bindings, and the overriding method replaces
some of them). I hope you know what I mean, describing complex
technical things in a foreign language is not the easiest thing to do.