Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,31 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
services.AddSingleton<IEntityTypeTemplateService, HbsEntityTypeTemplateService>();
services.AddSingleton<IModelCodeGenerator, HbsCSharpModelGenerator>();
services.AddSingleton<IReverseEngineerScaffolder, HbsReverseEngineerScaffolder>();
services.AddSingleton<IHbsHelperService>(provider =>
{
var helpers = new Dictionary<string, Action<TextWriter, object, object[]>>
{
{Constants.SpacesHelper, HandlebarsHelpers.SpacesHelper}
};
return new HbsHelperService(helpers);
});
return services;
}

/// <summary>
/// Register Handlebars helpers.
/// <para>
/// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsHelpers.
/// </para>
/// </summary>
/// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="handlebarsHelpers">Handlebars helpers.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddHandlebarsHelpers(this IServiceCollection services,
params (string helperName, Action<TextWriter, object, object[]> helperFunction)[] handlebarsHelpers)
{
services.AddSingleton<IHbsHelperService>(provider =>
{
var helpers = new Dictionary<string, Action<TextWriter, object, object[]>>
{
{Constants.SpacesHelper, HandlebarsHelpers.SpacesHelper}
};
handlebarsHelpers.ToList().ForEach(h => helpers.Add(h.helperName, h.helperFunction));
return new HbsHelperService(helpers);
});
var helperService = services.BuildServiceProvider().GetRequiredService<IHbsHelperService>();
handlebarsHelpers.ToList().ForEach(h => helperService.Helpers.Add(h.helperName, h.helperFunction));
return services;
}
}
Expand Down