Skip to content

Commit

Permalink
add extension method to ease registering classes in bootstrap installers
Browse files Browse the repository at this point in the history
  • Loading branch information
cYCL157 committed Apr 23, 2024
1 parent de06447 commit 3644b54
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Cortside.Common.BootStrap/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

namespace Cortside.Common.BootStrap {
public static class ServiceCollectionExtensions {
public static IServiceCollection RegisterClassesWithSuffix<T>(this IServiceCollection services, string suffix) where T : class {
/// <summary>
/// Add scoped classes with specified suffix from assembly that contains T
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="services"></param>
/// <param name="suffix"></param>
/// <returns></returns>
public static IServiceCollection AddScopedBySuffix<T>(this IServiceCollection services, string suffix) where T : class {
typeof(T).GetTypeInfo().Assembly.GetTypes()
.Where(x => (x.Name.EndsWith(suffix, StringComparison.InvariantCulture))
&& x.GetTypeInfo().IsClass
Expand Down

0 comments on commit 3644b54

Please sign in to comment.