November Happy Hour will be moved to Thursday December 5th.

dependency injection , what to use ?

Vote:
 

Hello Team,

I am new to EPiserver and I am looking for answer to question below:

what is the prffable ways to do the dependency injection , if I need to choose btween Strucurte Map , injected proprtey , service attrubte , constructor injecton ?

thanks

#216382
Feb 05, 2020 10:01
Vote:
 

Short answer: constructor injection whenever possible :)

#216383
Feb 05, 2020 10:09
Vote:
 

You are mixing things up a bit. StructureMap is the IoC (inversion of control) framework, and while it is the default IoC choice, you are quite free to choose other IoC like autofac (more work is needed, of course).

Service attribute is a way to register the implementation for the abstraction. I think it's OK but many developers prefer explicit registration. that's up to you.

there are 4 ways to get an instance of a dependency, in order of recommendation: constructor injection > injected property ~ service locator > new (). So yes, use constructor injector whenever possible 

#216386
Feb 05, 2020 10:15
Vote:
 

Thanks your quick answers :) 

#216391
Feb 05, 2020 11:23
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.