deanvmc
deanvmc

Reputation: 6095

Modifying and object returned .InRequestScope (Ninject)

If I ask for an object via injection and specify InRequestScope I am assuming that it returns the same instance until the request context changes. What I would like to know is if I modify that value will the next injection contain the modification?

Example (Pseudo):

 // In one class
 var Obj = kernel.Get<IObjType>();
 Obj.SomeProp = "Value"

 // In another class in the same request context.
 var Obj = kernel.Get<IObjType>();
 Assert.True(Obj.SomeProp = value);

Upvotes: 0

Views: 117

Answers (1)

Remo Gloor
Remo Gloor

Reputation: 32725

Short: Yes

Long: Within the same request Ninject will return the same object instance when it is in request scope.

This means your test will pass when the following test passes and the execution order of the two code snippets is correct.

Obj.SomeProp = "Value"
Assert.True(Obj.SomeProp == value);

Upvotes: 2

Related Questions