Kentico Cloud View Model - Locally cached & Strongly Typed?

The Kentico Cloud Deliver API uses a CDN internally so that your content is available anywhere in the world in a few milliseconds. Even with that awesome speed, wouldn't it be great to locally cache your content?

Also, what if you prefer working with strongly typed view models?

This is where the EmmTi.KenticoCloudConsumer.EnhancedDeliver NuGet package (still in beta) comes to the rescue.



Nuget Package

This project is available as a nuget package at https://www.nuget.org/packages/EmmTi.KenticoCloudConsumer.EnhancedDeliver/

To install EmmTi.KenticoCloudConsumer.EnhancedDeliver, run the following command in the Package Manager Console


Quick Setup Guide

Initial Setup

1. Follow the steps in the Kentico Dancing Goat Example to setup a sample site.
2. Add the following config setting in appsettings of web.config. Tweak the cache time as you see fit.


Creating the View Model

1. Create a new ViewModel and inherit from BaseContentItemViewModel
2. Add a ItemCodeName constant with the code name for the Kentico Content Type
3. Create public properties for other Content Elements
4. Override MapContentForType method and map each field - See example



The Controller

In your Controller return the new ViewModel using the DeliveryFactory



The View

Use the strongly typed model in your View



See a full sample site

Clone an enhanced version of the Dancing Goat Sample site for a working example
https://github.com/emmanueltissera/Deliver-Dancing-Goat-Enhanced

It's just got the Homepage View converted to a strongly typed, locally cached version. I will be updating the rest of the views and code as and when I get some time.

Source Code

The source code for EmmTi.KenticoCloudConsumer.EnhancedDeliver is available on github for you to fork and work on.
https://github.com/emmanueltissera/EmmTi.KenticoCloudConsumer.EnhancedDeliver

Contributions, pull requests and comments are welcome.


No comments:

Post a Comment