asp.net mvc - How does dependency injection container manage objects it didn't register? -


so read dependency injection in .net book not long ago. trying use dic now. however, have don't quite understand. 2 examples:

1. if have old code or 3rd party dll uses singleton static method this:

var objtool = thirdpartytool.getinstance(); objtool.dostuff(); ... 

2. if have code in method creating temp object:

var temporder = new order(); temporder.total = strarray.[0]; temporder.itemid = strarray.[1]; temporder.shipaddress = strarray[2]; if(customer.hasconfirmedorder) { customer.order = temporder; } ... 

in both cases, before enter dic world, know objects naturally gc collected when out of scope, or if there dispose() call, responsiable call somewhere after use object.

how dic treat them? (i running ninject on .net 4 mvc 3 project, guess other languages/projects , dics have pretty same structure)

if object not managed di framework, example provided, responsibility manage lifetime , if necessary call dispose on (especially if object implements idisposable)

so answer question:

how dic treat them?

it doesn't treat them @ all. di framework doesn't know of existence.

the di framework responsible managing objects explicitly registered it.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -