Context: Meta information for the current resolve. It specifies where in the object tree the currently resolved object will be injected into. (e.g. The currently resolved object will be injected into the constructor of class A, which is injected into class B, ....) It can be used for example to decide if a binding applies in the current context using one of the When
overloads. It is passed to many other callbacks of the fluent syntax as well (e.g. InScope, OnActivation, ....)
Scope: Defines the lifecycle of an object and when to reuse an existing instance, There are many predefined scopes as well as a generic one which can specify the scope from the current context (InScope(ctx => ...
)
Named Binding: Meta Information on the binding. Can be used in combination with context. E.g. The binding only applies when in the current context any of the parent bindings has some name.
Activation Block: (As of Ninject 2.x - 3.x, this will likely change in future versions). Within an activation block each bindings is changed to have the activation block as scope. This means the scope specified on the binding will be ignored. Exactly one instance will be created for resolves on one activation block.
I personally wouldn't use that feature because it is flawed by ignoring all kind of other scopes like InSingletonScope
. Better use the scopes given by Ninject.Extensions.NamedScope.
Regarding your example: Since you have two MyDbContext
bindings you will need to add conditions to them. e.g. WhenAnyAncestorNamed
. Or you could use another Scope like InCallScope()
with just one binding.