Try our conversational search powered by Generative AI!

dependency injection , what to use ?


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 ?


Feb 05, 2020 10:01

Short answer: constructor injection whenever possible :)

Feb 05, 2020 10:09

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 

Feb 05, 2020 10:15

Thanks your quick answers :) 

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.