1
- using System ;
2
- using System . Linq ;
3
- using System . Reactive . Subjects ;
4
- using System . Reflection ;
5
- using AutoMapper ;
6
- using Dotnet5 . GraphQL3 . Services . Abstractions . Messages ;
7
- using Microsoft . Extensions . DependencyInjection ;
8
- using Scrutor ;
9
-
10
- namespace Dotnet5 . GraphQL3 . Services . Abstractions . DependencyInjection
11
- {
12
- public static class ConfigureService
13
- {
14
- public static IServiceCollection AddApplicationServices ( this IServiceCollection services )
15
- => services . Scan ( selector
16
- => selector
17
- . FromApplicationDependencies ( assembly
18
- => assembly . FullName ? . StartsWith ( GetAssemblySuffix ( ) ) ?? default )
19
- . AddClasses ( filter
20
- => filter . AssignableToAny ( typeof ( IService < , , > ) ) )
21
- . UsingRegistrationStrategy ( RegistrationStrategy . Skip )
22
- . AsImplementedInterfaces ( )
23
- . WithScopedLifetime ( ) ) ;
24
-
25
- public static IServiceCollection AddMessageServices ( this IServiceCollection services )
26
- => services . Scan ( selector
27
- => selector
28
- . FromApplicationDependencies ( assembly
29
- => assembly . FullName ? . StartsWith ( GetAssemblySuffix ( ) ) ?? default )
30
- . AddClasses ( filter
31
- => filter . AssignableToAny ( typeof ( IMessageService < , , > ) ) )
32
- . UsingRegistrationStrategy ( RegistrationStrategy . Skip )
33
- . AsImplementedInterfaces ( )
34
- . WithSingletonLifetime ( ) ) ;
35
-
36
- public static IServiceCollection AddSubjects ( this IServiceCollection services )
37
- => services . AddSingleton ( typeof ( ISubject < > ) , typeof ( ReplaySubject < > ) ) ;
38
-
39
- public static IServiceCollection AddAutoMapper ( this IServiceCollection services )
40
- => services . AddAutoMapper (
41
- AppDomain . CurrentDomain . GetAssemblies ( )
42
- . Where ( x => x . FullName ?
43
- . Contains ( GetAssemblySuffix ( ) ) ?? false ) ) ;
44
-
45
- private static string GetAssemblySuffix ( )
46
- => Assembly . GetEntryAssembly ( ) ? . FullName ? . Substring ( 0 , 16 ) ;
47
- }
1
+ using System ;
2
+ using System . Linq ;
3
+ using System . Reactive . Subjects ;
4
+ using System . Reflection ;
5
+ using AutoMapper ;
6
+ using Dotnet5 . GraphQL3 . Services . Abstractions . Messages ;
7
+ using Microsoft . Extensions . DependencyInjection ;
8
+ using Scrutor ;
9
+
10
+ namespace Dotnet5 . GraphQL3 . Services . Abstractions . Extensions . DependencyInjection
11
+ {
12
+ public static class ServiceCollectionExtensions
13
+ {
14
+ public static IServiceCollection AddApplicationServices ( this IServiceCollection services )
15
+ => services . Scan ( selector
16
+ => selector
17
+ . FromApplicationDependencies ( assembly
18
+ => assembly . FullName ? . StartsWith ( GetAssemblySuffix ( ) ) ?? default )
19
+ . AddClasses ( filter
20
+ => filter . AssignableToAny ( typeof ( IService < , , > ) ) )
21
+ . UsingRegistrationStrategy ( RegistrationStrategy . Skip )
22
+ . AsImplementedInterfaces ( )
23
+ . WithScopedLifetime ( ) ) ;
24
+
25
+ public static IServiceCollection AddMessageServices ( this IServiceCollection services )
26
+ => services . Scan ( selector
27
+ => selector
28
+ . FromApplicationDependencies ( assembly
29
+ => assembly . FullName ? . StartsWith ( GetAssemblySuffix ( ) ) ?? default )
30
+ . AddClasses ( filter
31
+ => filter . AssignableToAny ( typeof ( IMessageService < , , > ) ) )
32
+ . UsingRegistrationStrategy ( RegistrationStrategy . Skip )
33
+ . AsImplementedInterfaces ( )
34
+ . WithSingletonLifetime ( ) ) ;
35
+
36
+ public static IServiceCollection AddSubjects ( this IServiceCollection services )
37
+ => services . AddSingleton ( typeof ( ISubject < > ) , typeof ( ReplaySubject < > ) ) ;
38
+
39
+ public static IServiceCollection AddAutoMapper ( this IServiceCollection services )
40
+ => services . AddAutoMapper (
41
+ AppDomain . CurrentDomain . GetAssemblies ( )
42
+ . Where ( x => x . FullName ?
43
+ . Contains ( GetAssemblySuffix ( ) ) ?? false ) ) ;
44
+
45
+ private static string GetAssemblySuffix ( )
46
+ => Assembly . GetEntryAssembly ( ) ? . FullName ? . Substring ( 0 , 16 ) ;
47
+ }
48
48
}
0 commit comments