Strongly Typed Topic Builder (.NET)

DXA's Model Builder pipeline handles content from Tridion Docs by automatically converting Generic Topic Models to Strongly Typed Topic Models. You can also use the public API to convert generic Topics to Strongly Typed Topic Models.

Model Builder Pipeline

The following code shows where DXA adds the StronglyTypedTopicBuilder model builder to Generic Topic Models to from the Model Builder Pipeline:

<modelBuilderPipeline>
  <add type="Sdl.Web.Tridion.Mapping.DefaultModelBuilder, Sdl.Web.Tridion" />
  <add type="Sdl.Web.Tridion.Mapping.StronglyTypedTopicBuilder, Sdl.Web.Tridion" />
</modelBuilderPipeline>

The Model Builder Pipeline uses StronglyTypedTopicBuilder only when both of the following are true:

  • A generic Topic is encountered
  • A Strongly Typed Topic Model has been registered

Strongly Typed Topic Conversion API

You can also use the StronglyTypedTopicBuilder class from the API to convert generic Topics to Strongly Typed Topic Models. The class exposes the following public methods for this purpose:

public EntityModel TryConvertToStronglyTypedTopic(GenericTopic genericTopic, Type ofType = null)
public T TryConvertToStronglyTypedTopic<T>(GenericTopic genericTopic) where T: EntityModel

These APIs facilitate two use cases:

  • The Strongly Typed Model Type should be data-driven 
    • The first method should be used with one parameter 
  • The Strongly Typed Model Type is known up front (e.g. because the View is known up front and an associated View Model is needed)
    • This first method can be used with two parameters
    • The second (generic) method can be used