@@ -30,11 +30,9 @@ public static class ServiceCollectionExtensions
3030 /// </summary>
3131 /// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
3232 /// <param name="options">Options for reverse engineering classes from an existing database.</param>
33- /// <param name="handlebarsHelpers">Handlebars helpers.</param>
3433 /// <returns>The same service collection so that multiple calls can be chained.</returns>
3534 public static IServiceCollection AddHandlebarsScaffolding ( this IServiceCollection services ,
36- ReverseEngineerOptions options = ReverseEngineerOptions . DbContextAndEntities ,
37- params ( string helperName , Action < TextWriter , object , object [ ] > helperFunction ) [ ] handlebarsHelpers )
35+ ReverseEngineerOptions options = ReverseEngineerOptions . DbContextAndEntities )
3836 {
3937 Type dbContextGeneratorImpl ;
4038 var dbContextGeneratorType = typeof ( ICSharpDbContextGenerator ) ;
@@ -59,15 +57,7 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
5957 services . AddSingleton < IEntityTypeTemplateService , HbsEntityTypeTemplateService > ( ) ;
6058 services . AddSingleton < IModelCodeGenerator , HbsCSharpModelGenerator > ( ) ;
6159 services . AddSingleton < IReverseEngineerScaffolder , HbsReverseEngineerScaffolder > ( ) ;
62- services . AddSingleton < IHbsHelperService > ( provider =>
63- {
64- var helpers = new Dictionary < string , Action < TextWriter , object , object [ ] > >
65- {
66- { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
67- } ;
68- handlebarsHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
69- return new HbsHelperService ( helpers ) ;
70- } ) ;
60+ services . AddSingleton < IHbsHelperService , HbsHelperService > ( ) ;
7161 return services ;
7262 }
7363
@@ -80,12 +70,18 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
8070 /// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
8171 /// <param name="handlebarsHelpers">Handlebars helpers.</param>
8272 /// <returns>The same service collection so that multiple calls can be chained.</returns>
83- [ Obsolete ( "AddHandlebarsHelpers has been deprecated. Pass helpers to AddHandlebarsScaffolding instead." ) ]
8473 public static IServiceCollection AddHandlebarsHelpers ( this IServiceCollection services ,
8574 params ( string helperName , Action < TextWriter , object , object [ ] > helperFunction ) [ ] handlebarsHelpers )
8675 {
87- var helperService = services . BuildServiceProvider ( ) . GetRequiredService < IHbsHelperService > ( ) ;
88- handlebarsHelpers . ToList ( ) . ForEach ( h => helperService . Helpers . Add ( h . helperName , h . helperFunction ) ) ;
76+ services . AddSingleton < IHbsHelperService > ( provider =>
77+ {
78+ var helpers = new Dictionary < string , Action < TextWriter , object , object [ ] > >
79+ {
80+ { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
81+ } ;
82+ handlebarsHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
83+ return new HbsHelperService ( helpers ) ;
84+ } ) ;
8985 return services ;
9086 }
9187 }
0 commit comments