This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.Handlebars/NitrideHandlebarsModule.cs

40 lines
1.0 KiB
C#

using System.Collections.Generic;
using Autofac;
using HandlebarsDotNet;
using MfGames.Nitride.Handlebars.Configuration;
namespace MfGames.Nitride.Handlebars;
public class NitrideHandlebarsModule : Module
{
/// <inheritdoc />
protected override void Load(ContainerBuilder builder)
{
builder.RegisterOperators(this);
builder.RegisterValidators(this);
builder.RegisterType<HandlebarsTemplateCache>()
.AsSelf()
.SingleInstance();
builder.Register(
(context) =>
{
IHandlebars handlebars = HandlebarsDotNet.Handlebars.Create();
IEnumerable<IHandlebarsLoader> helpers = context.Resolve<IEnumerable<IHandlebarsLoader>>();
foreach (IHandlebarsLoader helper in helpers)
{
helper.Register(handlebars);
}
return handlebars;
})
.As<IHandlebars>()
.SingleInstance();
}
}