@@ -57,27 +57,31 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
5757 services . AddSingleton < IEntityTypeTemplateService , HbsEntityTypeTemplateService > ( ) ;
5858 services . AddSingleton < IModelCodeGenerator , HbsCSharpModelGenerator > ( ) ;
5959 services . AddSingleton < IReverseEngineerScaffolder , HbsReverseEngineerScaffolder > ( ) ;
60+ services . AddSingleton < IHbsHelperService > ( provider =>
61+ {
62+ var helpers = new Dictionary < string , Action < TextWriter , object , object [ ] > >
63+ {
64+ { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
65+ } ;
66+ return new HbsHelperService ( helpers ) ;
67+ } ) ;
6068 return services ;
6169 }
6270
6371 /// <summary>
6472 /// Register Handlebars helpers.
73+ /// <para>
74+ /// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsHelpers.
75+ /// </para>
6576 /// </summary>
6677 /// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
6778 /// <param name="handlebarsHelpers">Handlebars helpers.</param>
6879 /// <returns>The same service collection so that multiple calls can be chained.</returns>
6980 public static IServiceCollection AddHandlebarsHelpers ( this IServiceCollection services ,
7081 params ( string helperName , Action < TextWriter , object , object [ ] > helperFunction ) [ ] handlebarsHelpers )
7182 {
72- services . AddSingleton < IHbsHelperService > ( provider =>
73- {
74- var helpers = new Dictionary < string , Action < TextWriter , object , object [ ] > >
75- {
76- { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
77- } ;
78- handlebarsHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
79- return new HbsHelperService ( helpers ) ;
80- } ) ;
83+ var helperService = services . BuildServiceProvider ( ) . GetRequiredService < IHbsHelperService > ( ) ;
84+ handlebarsHelpers . ToList ( ) . ForEach ( h => helperService . Helpers . Add ( h . helperName , h . helperFunction ) ) ;
8185 return services ;
8286 }
8387 }
0 commit comments