This repository was archived by the owner on Apr 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/NET6CustomLibrary/Scrutor Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ namespace NET6CustomLibrary . Scrutor ;
2+
3+ public static class ScrutorService
4+ {
5+ public static IServiceCollection AddRegisterTransientService < TAssembly > ( this IServiceCollection services , string stringEndsWith ) where TAssembly : class
6+ {
7+ services . Scan ( scan =>
8+ scan . FromAssemblyOf < TAssembly > ( )
9+ . AddClasses ( classes => classes . Where ( type => type . Name . EndsWith ( stringEndsWith ) ) )
10+ . AsImplementedInterfaces ( )
11+ . WithTransientLifetime ( ) ) ;
12+
13+ return services ;
14+ }
15+
16+ public static IServiceCollection AddRegisterSingletonService < TAssembly > ( this IServiceCollection services , string stringEndsWith ) where TAssembly : class
17+ {
18+ services . Scan ( scan =>
19+ scan . FromAssemblyOf < TAssembly > ( )
20+ . AddClasses ( classes => classes . Where ( type => type . Name . EndsWith ( stringEndsWith ) ) )
21+ . AsImplementedInterfaces ( )
22+ . WithSingletonLifetime ( ) ) ;
23+
24+ return services ;
25+ }
26+
27+ public static IServiceCollection AddRegisterScopedService < TAssembly > ( this IServiceCollection services , string stringEndsWith ) where TAssembly : class
28+ {
29+ services . Scan ( scan =>
30+ scan . FromAssemblyOf < TAssembly > ( )
31+ . AddClasses ( classes => classes . Where ( type => type . Name . EndsWith ( stringEndsWith ) ) )
32+ . AsImplementedInterfaces ( )
33+ . WithScopedLifetime ( ) ) ;
34+
35+ return services ;
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments