This repository was archived by the owner on May 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +42
-12
lines changed
src/AutoMapper.Extensions.Microsoft.DependencyInjection
test/AutoMapper.Extensions.Microsoft.DependencyInjection.Tests Expand file tree Collapse file tree 6 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -85,19 +85,11 @@ private static IServiceCollection AddAutoMapperClasses(IServiceCollection servic
8585 . SelectMany ( a => a . DefinedTypes )
8686 . ToArray ( ) ;
8787
88- var profileTypeInfo = typeof ( Profile ) . GetTypeInfo ( ) ;
89- var profiles = allTypes
90- . Where ( t => profileTypeInfo . IsAssignableFrom ( t ) && ! t . IsAbstract )
91- . ToArray ( ) ;
92-
9388 void ConfigAction ( IServiceProvider serviceProvider , IMapperConfigurationExpression cfg )
9489 {
9590 configAction ? . Invoke ( serviceProvider , cfg ) ;
9691
97- foreach ( var profile in profiles . Select ( t => t . AsType ( ) ) )
98- {
99- cfg . AddProfile ( profile ) ;
100- }
92+ cfg . AddMaps ( assembliesToScan ) ;
10193 }
10294
10395 var openTypes = new [ ]
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public void ShouldResolveConfiguration()
2828 [ Fact ]
2929 public void ShouldConfigureProfiles ( )
3030 {
31- _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 2 ) ;
31+ _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 3 ) ;
3232 }
3333
3434 [ Fact ]
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ public void ShouldResolveConfiguration()
3333 [ Fact ]
3434 public void ShouldConfigureProfiles ( )
3535 {
36- _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 2 ) ;
36+ _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 3 ) ;
3737 }
3838
3939 [ Fact ]
Original file line number Diff line number Diff line change 1+ using System ;
2+ using Microsoft . Extensions . DependencyInjection ;
3+ using Shouldly ;
4+ using Xunit ;
5+
6+ namespace AutoMapper . Extensions . Microsoft . DependencyInjection . Tests
7+ {
8+ public class AttributeTests
9+ {
10+ [ Fact ]
11+ public void Should_not_register_static_instance_when_configured ( )
12+ {
13+ IServiceCollection services = new ServiceCollection ( ) ;
14+ services . AddAutoMapper ( cfg => cfg . CreateMissingTypeMaps = false , typeof ( Source3 ) ) ;
15+
16+ var serviceProvider = services . BuildServiceProvider ( ) ;
17+
18+ var mapper = serviceProvider . GetService < IMapper > ( ) ;
19+
20+ var source = new Source3 { Value = 3 } ;
21+
22+ var dest = mapper . Map < Dest3 > ( source ) ;
23+
24+ dest . Value . ShouldBe ( source . Value ) ;
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ public class Dest2
2121 public int ConvertedValue { get ; set ; }
2222 }
2323
24+ public class Source3
25+ {
26+ public int Value { get ; set ; }
27+ }
28+
29+ [ AutoMap ( typeof ( Source3 ) ) ]
30+ public class Dest3
31+ {
32+ public int Value { get ; set ; }
33+ }
34+
2435 public class Profile1 : Profile
2536 {
2637 public Profile1 ( )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public void ShouldResolveConfiguration()
2626 [ Fact ]
2727 public void ShouldConfigureProfiles ( )
2828 {
29- _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 2 ) ;
29+ _provider . GetService < IConfigurationProvider > ( ) . GetAllTypeMaps ( ) . Length . ShouldBe ( 3 ) ;
3030 }
3131
3232 [ Fact ]
You can’t perform that action at this time.
0 commit comments