In yesterday’s #dd4tdaily post I explained how to setup a default REST service using DD4T 2.0.
As always, implementation specific logic is required, like implementing logic to retrieve data from Tridion using the Content Delivery API (e.g. selecting components based on a keyword). For these situations you will need to write your own Controllers and Classes to providing the required logic. We first need a Controller, so we create a class for this (keep in mind class names must end with ‘Controller’).
Now we have a new Controller but this needs to get wired up to the DD4T.RestService.WebApi. In the root of the solution you will a find a Startup.cs file. In this file we need to register the new controller into our DI container. DD4T.RestService.WebApi uses Autofac as a Dependency injection (DI) container.
The controller is now added to a container and that container is used as base container to register the DD4T internal dependencies. Your controller is ready for use.