InitializationModule, context.Locate.Advanced vs ServiceLocator.Current

Vote:
 

Hi

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?

#88962
Aug 05, 2014 9:05
Vote:
 

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.

#90422
Sep 09, 2014 13:25