inject dependencies methods constructor?


dependency injection seems good thing. general, should dependencies injected during methods need them, should injected contructor class?



see samples next denote twin ways inject same dependency.



//inject dependency methods need importantclass
class something {

open something()
{
//empty
}

open vacant a()
{
//do something but x
}

open vacant b(importantclass x)
{
//do something x
}

open vacant c(importantclass x)
{
//do something x
}
}

//inject dependency constructor once
class something {
private importantclass _x
open something(importantclass x)
{
this._x = x;
}

open vacant a()
{
//do something but x
}

open vacant b()
{
//do something this._x
}

open vacant c()
{
//do something this._x
}

}


Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members