I'm new to DXA and faced an unknown while fetching DCP (or to say EntityModel) from other Publication. I've a pre populated Localization object which points to current Publication/site context. How can I get a Localization object for a different Publication?

My requirement is to fetch EntityModels from a different Publication then current!

I know, we get can EntityModel for current Publication like this:

DefaultContentProvider contentProvider = new DefaultContentProvider();
EventDetail eventDataModel = null;
    var eventData = contentProvider.GetEntityModel(new TcmUri(compId).ItemId + "-" + EventDetailCTID, _localization);
    eventDataModel = eventData as EventDetail;
catch (Exception e)
    // Error

How can we get a _localization object for some other Publication?

Use Case: Every locale specific dynamic components are published from each publications. There is a webpage where we want to display all these dynamic components (from all geos), on a single page.

Update: I found a way of getting the localization object using Resolver: ILocalizationResolver localizationResolver = new CdApiLocalizationResolver(); _localization = localizationResolver.ResolveLocalization(new Uri());

I tried localizationResolver.GetLocalization(), but this doesnt seems to build the object.

  • 2
    DXA isn't designed to work like you are trying to use it, the Localizations/Publications are there to separate sites completely. So I'm really wondering about the actual use case you have to fetch an Entity from a different Publication, perhaps if we know more about the use case we can think of a different solution (maybe BluePrinting can help etc.). so I suggest you edit your question and supply some more details. Oct 3 '17 at 7:31
  • 1
    BTW: you should not instantiate Providers/Resolvers yourself, but use SiteConfiguration.ContentProvider and SiteConfiguration.LocalizationResolver to get instances of configured types (dependency injection). Oct 3 '17 at 18:37
  • Added the use case @BartKoopman. Sure will use SIteConfiguration Oct 4 '17 at 19:05

Although your use case is still not really clear (and thus it is not clear if your really have to use cross-Localization logic), there is a way to ensure that a Localization object retrieved from ILocalizationResolver.GetLocalization is initialized:

Localization loc = SiteConfiguration.LocalizationResolver.GetLocalization(id);
  • Rick - I just updated my use case. Thx for providing this method call. Oct 15 '17 at 21:25
  • What id are we expecting here? A full tcmid, e.g. tcm:0-303-1 or just the publication number, e.g. 303 or something else as it doesn't seem to work for me. I can get the localization using ResolveLocalization(domain) but in my current situation I don't have the domain, only the piblication Id of 303.
    – Percy
    Feb 7 '20 at 13:47
  • The ID of a DXA Localization is indeed just a number; the middle part of the Publication TCM URI. Feb 7 '20 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.