@@ -17,14 +17,60 @@ namespace Microsoft.EntityFrameworkCore.Design
1717 /// </summary>
1818 public static class ServiceCollectionExtensions
1919 {
20+ #region Methods
21+
22+ /// <summary>
23+ /// Register Handlebars block helpers.
24+ /// <para>
25+ /// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsBlockHelpers.
26+ /// </para> /// </summary>
27+ /// <param name="services">The <see cref="IServiceCollection" /> to add services to. </param>
28+ /// <param name="handlebarsBlockHelpers">Handlebars block helpers.</param>
29+ /// <returns></returns>
30+ public static IServiceCollection AddHandlebarsBlockHelpers ( this IServiceCollection services ,
31+ params ( string helperName , Action < TextWriter , HelperOptions , Dictionary < string , object > , object [ ] > helperFunction ) [ ] handlebarsBlockHelpers )
32+ {
33+ services . AddSingleton < IHbsBlockHelperService > ( provider =>
34+ {
35+ var helpers = new Dictionary < string , Action < TextWriter , HelperOptions , Dictionary < string , object > , object [ ] > > ( ) ;
36+ handlebarsBlockHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
37+ return new HbsBlockHelperService ( helpers ) ;
38+ } ) ;
39+ return services ;
40+ }
41+
42+ /// <summary>
43+ /// Register Handlebars helpers.
44+ /// <para>
45+ /// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsHelpers.
46+ /// </para>
47+ /// </summary>
48+ /// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
49+ /// <param name="handlebarsHelpers">Handlebars helpers.</param>
50+ /// <returns>The same service collection so that multiple calls can be chained.</returns>
51+ public static IServiceCollection AddHandlebarsHelpers ( this IServiceCollection services ,
52+ params ( string helperName , Action < TextWriter , Dictionary < string , object > , object [ ] > helperFunction ) [ ] handlebarsHelpers )
53+ {
54+ services . AddSingleton < IHbsHelperService > ( provider =>
55+ {
56+ var helpers = new Dictionary < string , Action < TextWriter , Dictionary < string , object > , object [ ] > >
57+ {
58+ { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
59+ } ;
60+ handlebarsHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
61+ return new HbsHelperService ( helpers ) ;
62+ } ) ;
63+ return services ;
64+ }
65+
2066 /// <summary>
2167 /// <para>
2268 /// Registers the Handlebars scaffolding generator as a service in the <see cref="IServiceCollection" />.
23- /// This allows you to customize generated DbContext and entity type classes by modifying the Handlebars
69+ /// This allows you to customize generated DbContext and entity type classes by modifying the Handlebars
2470 /// templates in the CodeTemplates folder.
2571 /// </para>
2672 /// <para>
27- /// Has <paramref name="options" /> that allow you to choose whether to generate only the DbContext class,
73+ /// Has <paramref name="options" /> that allow you to choose whether to generate only the DbContext class,
2874 /// only entity type classes, or both DbContext and entity type classes (the default).
2975 /// </para>
3076 /// </summary>
@@ -46,11 +92,11 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
4692 /// <summary>
4793 /// <para>
4894 /// Registers the Handlebars scaffolding generator as a service in the <see cref="IServiceCollection" />.
49- /// This allows you to customize generated DbContext and entity type classes by modifying the Handlebars
95+ /// This allows you to customize generated DbContext and entity type classes by modifying the Handlebars
5096 /// templates in the CodeTemplates folder.
5197 /// </para>
5298 /// <para>
53- /// Has <paramref name="configureOptions" /> that allow you to choose whether to generate only the DbContext class,
99+ /// Has <paramref name="configureOptions" /> that allow you to choose whether to generate only the DbContext class,
54100 /// only entity type classes, or both DbContext and entity type classes (the default).
55101 /// It also allows you to exclude tables from the generation.
56102 /// This can be useful when placing model classes in a separate class library.
@@ -106,6 +152,11 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
106152 services . AddSingleton < ITemplateLanguageService , CSharpTemplateLanguageService > ( ) ;
107153 }
108154
155+ if ( scaffoldingOptions . PluralizerOptions == PluralizerOptions . UseHumanizerPluralization )
156+ {
157+ services . AddSingleton < IPluralizer , HumanizerPluralizer > ( ) ;
158+ }
159+
109160 if ( scaffoldingOptions . EmbeddedTemplatesAssembly != null )
110161 {
111162 services . AddSingleton < ITemplateFileService > ( new EmbeddedResourceTemplateFileService (
@@ -136,50 +187,6 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
136187 return services ;
137188 }
138189
139- /// <summary>
140- /// Register Handlebars helpers.
141- /// <para>
142- /// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsHelpers.
143- /// </para>
144- /// </summary>
145- /// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
146- /// <param name="handlebarsHelpers">Handlebars helpers.</param>
147- /// <returns>The same service collection so that multiple calls can be chained.</returns>
148- public static IServiceCollection AddHandlebarsHelpers ( this IServiceCollection services ,
149- params ( string helperName , Action < TextWriter , Dictionary < string , object > , object [ ] > helperFunction ) [ ] handlebarsHelpers )
150- {
151- services . AddSingleton < IHbsHelperService > ( provider =>
152- {
153- var helpers = new Dictionary < string , Action < TextWriter , Dictionary < string , object > , object [ ] > >
154- {
155- { Constants . SpacesHelper , HandlebarsHelpers . SpacesHelper }
156- } ;
157- handlebarsHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
158- return new HbsHelperService ( helpers ) ;
159- } ) ;
160- return services ;
161- }
162-
163- /// <summary>
164- /// Register Handlebars block helpers.
165- /// <para>
166- /// Note: You must first call AddHandlebarsScaffolding before calling AddHandlebarsBlockHelpers.
167- /// </para> /// </summary>
168- /// <param name="services">The <see cref="IServiceCollection" /> to add services to. </param>
169- /// <param name="handlebarsBlockHelpers">Handlebars block helpers.</param>
170- /// <returns></returns>
171- public static IServiceCollection AddHandlebarsBlockHelpers ( this IServiceCollection services ,
172- params ( string helperName , Action < TextWriter , HelperOptions , Dictionary < string , object > , object [ ] > helperFunction ) [ ] handlebarsBlockHelpers )
173- {
174- services . AddSingleton < IHbsBlockHelperService > ( provider =>
175- {
176- var helpers = new Dictionary < string , Action < TextWriter , HelperOptions , Dictionary < string , object > , object [ ] > > ( ) ;
177- handlebarsBlockHelpers . ToList ( ) . ForEach ( h => helpers . Add ( h . helperName , h . helperFunction ) ) ;
178- return new HbsBlockHelperService ( helpers ) ;
179- } ) ;
180- return services ;
181- }
182-
183190 /// <summary>
184191 /// Register Handlebars transformers.
185192 /// <para>
@@ -209,5 +216,7 @@ public static IServiceCollection AddHandlebarsTransformers(this IServiceCollecti
209216 navPropertyTransformer ) ) ;
210217 return services ;
211218 }
219+
220+ #endregion
212221 }
213- }
222+ }
0 commit comments