Skip to content

1.0 Getting started with .NET

Quirijn edited this page Jul 4, 2016 · 7 revisions

This page describes how to get started with the .NET version of the DD4T 2.0 framework.

Note: We are in the process of updating this page, please also read this blog post:

This assumes familiarity with ASP.NET MVC. If you are not familiar with the MVC concepts and framework you should start there before attempting to implement DD4T.

At its core DD4T publishes data to the SDL Tridion/Web Content Data Store as JSON and the MVC framework uses the URL to determine which data to pull.

Installing the DD4T templates

Downloading and running the installer

  • Download the zip package from here and unpack it.
  • Run the install-templates.bat and follow the steps.

It couldn't be easier!

Create a template metadata schema

This step is not strictly necessary, but it's recommended. If you don't, the names of the templates are mapped to the names of Razor views in your web application.

Create a metadata schema called 'Page Template Metadata', and add a single-value text field called 'view' (XML name). Create a second metadata called 'Component Template Metadata' with the following single-value text fields: view, controller, action. All fields must be optional.

Creating your first Page Template

Open the SDL Tridion Template Builder (if you don't have it installed, start Internet Explorer and browse to any Tridion CME, then click on the Tools ribbon and download the template builder from there).

Create a page template, give it any name you like, and add the 'Generate dynamic page' DD4T template building block to it. Save and close the template.

Open the component template again, but this time from the CME. Assign the Page Template Metadata, and make sure the 'view' field has a short, logical name. The web application expects a Razor view with that same name, so don't include spaces and other funny characters. Also, do NOT add '.cshtml'. Just the file name part of the view without the extension!

Creating your first Component Template

Create a component template, give it any name you like, and add the 'Generate dynamic component presentation' DD4T template building block to it. Save and close the template. Open the component template again, but this time from the CME. Link it to one ore more schemas. Also, assign the Component Template Metadata and supply a view name (see above). Don't worry about the controller and action fields for now.

You are now ready to publish pages.

Creating a DD4T Web Application with MVC

  • Open Visual Studio
  • Create a new ASP.NET Web Application
    • Select Empty as a template
    • Under "Add folders and core references for:" select MVC
    • Uncheck "Host in the cloud" (Unless you want to create an Azure hosted application)
    • If you want Unit Tests, select the option
    • Click OK
  • Now your project is created, go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution
    • If you forgot to (or on purpose) didn't check the MVC files, the following library will install it for you.
    • If you want an alpha or beta release select "Include prerelease".
    • Search for DD4T.MVC5 and install it (By default your MVC version is the latest stable version, that is MVC 5 currently)
    • This will automatically install the DD4T.Core and the DD4T.Model.
    • Choose a Dependency Injection provider my either searching and installing one of the following packages:
      • DD4T.DI.Autofac
      • DD4T.DI.Ninject
      • DD4T.DI.Unity
    • Depending on your SDL Tridion version or running the Rest service also search for and install one of the following packages:
      • DD4T.Providers.SDLTridion2011sp1
      • DD4T.Providers.SDLTridion2013
      • DD4T.Providers.SDLTridion2013sp1
      • DD4T.Providers.Rest
    • These are the DD4T dependencies you need.
    • If you have installed one of the SDL Tridion Providers do the following:
      • Grab your SDL Tridion Content Delivery DLL's and put them in the bin folder.
      • Grab your SDL Tridion Content Delivery jar files and put them in the bin\lib folder
      • Grab your SDL Tridion Content Delivery Configuration files (cd_storage.conf etc..) and put them in the bin\config folder

      This could be done differently and provides a way to keep the bin folder clean. There is a way described on my blog here.

Wire up your application

The last thing to do is to configure dependency injection for your application. This is done in the Global.asax.cs (which should be in the root folder of your web application).

This example uses Autofac, and also relies on the Autofac.Mvc5 NuGet package.

Add the following code to this class:

public class MvcApplication : HttpApplication
    private ILifetimeScope DD4T_Start()
        var builder = new ContainerBuilder();

        // register MVC controllers
        return builder.Build();

    protected void Application_Start()
        var diContainer = DD4T_Start();
        DependencyResolver.SetResolver(new AutofacDependencyResolver(diContainer));

Run the application, you're good to go!

You can’t perform that action at this time.