You need a handlebars frontend with a specific file structure (learn more about that here) or a Nitro project as a precondition of this installation manual.
Create a ASP.NET MVC solution on your local machine with Visual Studio and compile the solution.
There are several ways to install NitroNet. The easiest way is to use NitroNet together with Unity or CastleWindsor.
Please choose between variant
- A with Unity or CastleWindsor
- B with another IoC Framework.
Execute the following line in your NuGet Package Manager to install NitroNet for Sitecore with your preferred IoC framework:
PM >
Install-Package NitroNet.UnityModules
In addition, it is recommended to install the Unity.Mvc which is a lightweight Unity bootstrapper for MVC applications:
PM >
Install-Package Unity.Mvc
PM >
Install-Package NitroNet.CastleWindsorModules
To activate NitroNet it's important to add/register the new view engine in your application. You can do this, with this line of code (Gist):
protected void Application_Start()
{
// ...
ViewEngines.Engines.Add(DependencyResolver.Current.GetService<NitroNetViewEngine>());
}
And add this using statements to Global.asax(.cs): using NitroNet.Mvc;
To activate NitroNet with Unity, please add these lines to /App_Start/UnityConfig.cs in the RegisterTypes() method (Gist):
public static void RegisterTypes(IUnityContainer container)
{
var rootPath = HostingEnvironment.MapPath("~/");
var basePath = PathInfo.Combine(PathInfo.Create(rootPath), PathInfo.Create(ConfigurationManager.AppSettings["NitroNet.BasePath"])).ToString();
new DefaultUnityModule(basePath).Configure(container);
}
To activate NitroNet with CastleWindsor, please add these lines to your application:
public static void RegisterTypes(IWindsorContainer container)
{
var rootPath = HostingEnvironment.MapPath("~/");
var basePath = PathInfo.Combine(PathInfo.Create(rootPath), PathInfo.Create(ConfigurationManager.AppSettings["NitroNet.BasePath"])).ToString();
new DefaultCastleWindsorModule(basePath).Configure(container);
}
You will need the following using statements for the previously mentioned lines of code:
using System.Configuration;
using System.Web.Hosting;
using NitroNet.UnityModules;
using NitroNet.ViewEngine.IO;
You don't like Unity and you design your application with an other IoC framework? No Problem. In this case, you can install NitroNet only with the base package:
PM >
Install-Package NitroNet.Core
Please extend your Global.asax(.cs) in the same way as in scenario A
Actually, we only made a Unity and CastleWindsor integration with NitroNet. But it's easy to use another IoC Framework. Please follow our Unity sample as a template for you (Gist):
using System.Web;
using Microsoft.Practices.Unity;
using NitroNet.Mvc;
using NitroNet.ViewEngine;
using NitroNet.ViewEngine.Cache;
using NitroNet.ViewEngine.Config;
using NitroNet.ViewEngine.IO;
using NitroNet.ViewEngine.TemplateHandler;
using NitroNet.ViewEngine.ViewEngines;
using Veil.Compiler;
using Veil.Helper;
namespace NitroNet.UnityModules
{
public class DefaultUnityModule : IUnityModule
{
private readonly string _basePath;
public DefaultUnityModule(string basePath)
{
_basePath = basePath;
}
public void Configure(IUnityContainer container)
{
RegisterConfiguration(container);
RegisterApplication(container);
}
protected virtual void RegisterConfiguration(IUnityContainer container)
{
var config = ConfigurationLoader.LoadNitroConfiguration(_basePath);
container.RegisterInstance(config);
container.RegisterInstance<IFileSystem>(new FileSystem(_basePath, config));
}
protected virtual void RegisterApplication(IUnityContainer container)
{
container.RegisterType<IHelperHandlerFactory, DefaultRenderingHelperHandlerFactory>(
new ContainerControlledLifetimeManager());
container.RegisterType<IMemberLocator, MemberLocatorFromNamingRule>();
container.RegisterType<INamingRule, NamingRule>();
container.RegisterType<IModelTypeProvider, DefaultModelTypeProvider>();
container.RegisterType<IViewEngine, VeilViewEngine>();
container.RegisterType<ICacheProvider, MemoryCacheProvider>();
container.RegisterType<IComponentRepository, DefaultComponentRepository>(new ContainerControlledLifetimeManager());
container.RegisterType<ITemplateRepository, NitroTemplateRepository>(new ContainerControlledLifetimeManager());
container.RegisterType<INitroTemplateHandlerFactory, MvcNitroTemplateHandlerFactory>(
new ContainerControlledLifetimeManager());
}
}
}