orourkedd
orourkedd

Reputation: 6421

Ninject Context Uniqueness

I'm writing a Ninject extension and have some questions about the internals of Ninject. Is the following true?

  1. It seems like each activated instance has a distinct IContext associated with it.

  2. Contexts cannot be recycled. Once the object associated w a context has been created (ie the IObject in Bind<IObject>.To...), that context cannot be reused to create another object. The next time the binding is resolved, it will use a newly created context.

Upvotes: 1

Views: 75

Answers (1)

Remo Gloor
Remo Gloor

Reputation: 32725

Context gives you the context information for the currently activated object. E.g. what type, where it will be injected into, ....

This information is different for every activated object, So yes a new instance will be created for each activated object. Also the context is created before the object is activated.

Upvotes: 2

Related Questions