Faster application startup (.NET)
Several improvements improve the speed at which the application starts, but this does result in some API changes.
Before SDL Digital Experience Accelerator 1.1, a bootstrap process used the file /system/_all.json to serialize all configuration files for all localizations that you specified in cd_dynamic_conf.xml.
As of DXA 1.1, serialization takes place on demand, per localization and per setting type. If your Web application contains a large number of sites or localizations, this leads to a noticeably faster startup of your application.
- The
IStaticFileManager.CreateStaticAssetsmethod is now obsolete. - The
Serializemethod now has aLocalizationparameter.
Similarly, before DXA 1.1, you could rely on the product to populate the ViewModelRegistry, which stores the mapping between a View and the View Model type, for you. This required the View to be compiled and the View Model type to be determined, resulting in slow initial page rendering after application startup.
AreaConfiguration class to populate the registry with all the views in your Area. To achieve this, make your Area Registration class inherit from Sdl.Web.Mvc.Configurations.BaseAreaRegistration and override the RegisterAllViewModels method as follows:
package com.sdl.webapp.main;
import com.sdl.webapp.common.api.model.ViewModelRegistry;
import com.sdl.webapp.common.api.model.entity.*;
import com.sdl.webapp.common.api.model.page.PageModelImpl;
import com.sdl.webapp.common.api.model.region.RegionModelImpl;
import com.sdl.webapp.common.exceptions.DxaException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class CoreInitializer {
private final ViewModelRegistry viewModelRegistry;
@Autowired
public CoreInitializer(ViewModelRegistry viewModelRegistry) {
this.viewModelRegistry = viewModelRegistry;
}
@PostConstruct
public void registerViewModelEntityClasses() {
try {
viewModelRegistry.registerViewEntityClass("Article", Article.class);
viewModelRegistry.registerViewEntityClass("Breadcrumb", NavigationLinks.class);
<code omitted for brevity>
} catch (DxaException e) {
//LOG errors
}
}
}
package com.sdl.webapp.common.api.formatters;
import com.sdl.webapp.common.api.WebRequestContext;
import com.sdl.webapp.common.api.model.entity.Teaser;
import javax.servlet.http.HttpServletRequest;
import java.net.URISyntaxException;
/**
* Produces the feed in other format
*/
public class MyCustomFormatter extends BaseFormatter {
public MyCustomFormatter(HttpServletRequest request, WebRequestContext context) {
super(request, context);
this.addMediaType("mimetype-1");
//you can add more than one mimetype
this.addMediaType("mimetype-2");
}
/**
* Returns the formatted data. Additional model processing can be implemented in extending classes
* @param model
* @return
*/
@Override
public Object formatData(Object model) {
//perform actions here to change the data to any format you want
}
/**
* @param item
* @return
* @throws URISyntaxException
*/
@Override
public Object getSyndicationItemFromTeaser(Teaser item) throws Exception {
// add code here to transform a teaser into a new entry
}
}
Alternatively, you can choose to not override RegisterAllViewModels. In that case, DXA uses the default implementation of that method, which scans the file system for Views and compiles them to determine the Model type, as before. But as before, this approach delays application startup, especially if you have many Views or folders to scan.