Try our conversational search powered by Generative AI!

InitializationModule, context.Locate.Advanced vs ServiceLocator.Current



Maybe mainly question to EPiServer personel but which one we should actually use in initialization modules?

I can see with ILSpy the difference mainly that the context.Locate always does new ServiceLocationHelper(...)

- so if using the context and you need many services then you should get a local scope reference to the ServiceLocationHelper

var helper = context.Locate;

- and then use that to get the services

- if using the ServiceLocator.Current then you can keep calling that property for all the service requests

But is there any difference which to use?

Aug 05, 2014 9:05

The ServiceLocationHelper has some extension methods (in namespace EPiServer I think) that make it easier to get e.g. a content repository. The class is very thin and basically exists only to make it possible to add these extension methods, so it should be cheap to instantiate.

There should be no difference in the container contents between ServiceLocator.Current and context.Locate.Advanced though.

Sep 09, 2014 13:25
* 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.