Setup

If you’re looking for the super short quick setup then stick to the bits in bold.

Registering the Fortis interfaces

Fortis has been built with the use of dependency injection in mind and therefore we highly recommend using a dependency injection framework for setting Fortis up. The below show’s how to set Fortis up using SimpleInjector, a light, fast and easy to use framework. An excellent resource showing comparisons and benchmarks between different dependency injection frameworks see Daniel Palme’s article which is updated regularly.

You’ll need to register the following interfaces along with their corresponding concrete classes as a singleton:

  • Fortis.Model.IItemFactory
  • Fortis.Providers.IContextProvider
  • Fortis.Providers.ISpawnProvider
  • Fortis.Providers.ITemplateMapProvider
  • Fortis.Providers.IModelAssemblyProvider
  • Fortis.Search.IItemSearchFactory

As Fortis uses interfaces with constructor dependency injection you’re able to map different implementations. For example the implementation of the ITemplateMapProvider Fortis ships with relies on the IModelAssemblyProvider, this could be replaced with a different means of providing the template map.

After the interfaces have been registered Fortis requires some initialisation which populates two objects:

  • Fortis.Global.ItemFactory
  • Fortis.Global.SpawnProvider

While Fortis tries to use dependency injection where possible these global objects are used when implementing any Sitecore pipelines and events. We don’t recommend using these properties throughout your implementation and use constructor dependency injection where you require the IItemFactory.

Sitecore 7.X/MVC using SimpleInjector

namespace MySitecoreWebsite
{
    public class Global : Sitecore.Web.Application
    {
        var container = new Container();

        // Register Fortis
        container.Register<IItemFactory, ItemFactory>(Lifestyle.Singleton);
        container.Register<IContextProvider, ContextProvider>(Lifestyle.Singleton);
        container.Register<ISpawnProvider, SpawnProvider>(Lifestyle.Singleton);
        container.Register<ITemplateMapProvider, TemplateMapProvider>(Lifestyle.Singleton);
        container.Register<IModelAssemblyProvider, ModelAssemblyProvider>(Lifestyle.Singleton);
        container.Register<IItemSearchFactory, ItemSearchFactory>(Lifestyle.Singleton);

        // Initialise fortis - this is required for places where we can't use DI
        Global.Initialise(
            container.GetInstance<ISpawnProvider>(),
            container.GetInstance<IItemFactory>()
        );

        // Register the container as MVC IDependencyResolver.
        DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
    }
}

Sitecore Configuration

[Optional] To enable the Fortis presentation engine, the following configuration file should be added to the /App_Config/Includes folder in your project – this is optional and only if you need to use Fortis rendering options. 

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"?>
    <sitecore>
        <pipelines>
            <renderField>
                <processor type="Fortis.Pipelines.RenderField.LinkRenderer, Fortis" patch:before="processor[@type='Sitecore.Pipelines.RenderField.AddBeforeAndAfterValues, Sitecore.Kernel']" />
            </renderField>
        </pipelines>
    </sitecore>
</configuration>

Web.config Configuration

If you’re planning on using the out of the box ModelAssemblyProvider you’ll need to add the following to the Web.config. Replace the {Model Project} with the assembly that contains all your modelled classes.

<configuration>
    <configSections>
        <section name="fortis" type="System.Configuration.NameValueSectionHandler" />
    </configSections>
    <fortis>
        <add key="assembly" value="{Model Project}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </fortis>
</configuration>

Next: Model Templates