1

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;
try
{
    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. – Bart Koopman 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). – Rick Pannekoek Oct 3 '17 at 18:37
  • Added the use case @BartKoopman. Sure will use SIteConfiguration – Rohan Gadiya Oct 4 '17 at 19:05
2

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);
loc.EnsureInitialized();
  • Rick - I just updated my use case. Thx for providing this method call. – Rohan Gadiya Oct 15 '17 at 21:25

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.