Context: Meta information for the current resolution. It determines where in the tree of objects the current allowed object will be entered. (for example, the object currently resolved will be introduced into the constructor of class A, which is introduced into class B, ....) It can be used, for example, to determine whether binding is applied in the current context using one of the When overloads . It is also passed to many other callbacks in free syntax (e.g. InScope, OnActivation, ....)
Scope: Defines the life cycle of an object and reuse of an existing instance. There are many predefined areas, as well as a general one, which can determine the scope from the current context ( InScope(ctx => ... )
Named binding: Meta information about the binding. It can be used in combination with context. For instance. A binding only applies when in the current context any of the parent bindings has a name.
Activation block: (compared to Ninject 2.x - 3.x this is likely to change in future versions). Inside the activation block, each binding changes so that the activation block is like a scope. This means that the area specified in the binding will be ignored. Exactly one instance will be created for resolution on one activation unit.
I personally will not use this function because it is erroneous, ignoring all kinds of other areas, for example InSingletonScope . It is better to use the areas defined by Ninject.Extensions.NamedScope.
As for your example: since you have two MyDbContext bindings, you will need to add conditions to them. e.g. WhenAnyAncestorNamed . Or you can use another Scope, such as InCallScope() , with one binding.
source share