Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit bb72f7d

Browse files
committed
Updating to 11.0.0
1 parent 6f6c1c5 commit bb72f7d

File tree

5 files changed

+74
-80
lines changed

5 files changed

+74
-80
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
jobs:
1111
build:
1212
strategy:
13+
matrix:
14+
os: [windows-latest]
1315
fail-fast: false
1416
runs-on: windows-latest
1517
steps:

src/AutoMapper.Extensions.Microsoft.DependencyInjection/AutoMapper.Extensions.Microsoft.DependencyInjection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="AutoMapper" Version="10.1.2-alpha.0.4" />
24+
<PackageReference Include="AutoMapper" Version="11.0.0" />
2525
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
2626
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
2727
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All" />

src/TestApp/Program.cs

Lines changed: 67 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,94 @@
1-
using System;
2-
3-
namespace TestApp
1+
using AutoMapper;
2+
using AutoMapper.Internal;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
IServiceCollection services = new ServiceCollection();
6+
services.AddTransient<ISomeService>(sp => new FooService(5));
7+
services.AddAutoMapper(typeof(Source));
8+
var provider = services.BuildServiceProvider();
9+
using (var scope = provider.CreateScope())
410
{
5-
using AutoMapper;
6-
using AutoMapper.Internal;
7-
using Microsoft.Extensions.DependencyInjection;
11+
var mapper = scope.ServiceProvider.GetRequiredService<IMapper>();
812

9-
public class Program
13+
foreach (var typeMap in mapper.ConfigurationProvider.Internal().GetAllTypeMaps())
1014
{
11-
public static void Main(string[] args)
12-
{
13-
IServiceCollection services = new ServiceCollection();
14-
services.AddTransient<ISomeService>(sp => new FooService(5));
15-
services.AddAutoMapper(typeof(Source));
16-
var provider = services.BuildServiceProvider();
17-
using (var scope = provider.CreateScope())
18-
{
19-
var mapper = scope.ServiceProvider.GetService<IMapper>();
20-
21-
foreach (var typeMap in mapper.ConfigurationProvider.Internal().GetAllTypeMaps())
22-
{
23-
Console.WriteLine($"{typeMap.SourceType.Name} -> {typeMap.DestinationType.Name}");
24-
}
25-
26-
foreach (var service in services)
27-
{
28-
Console.WriteLine(service.ServiceType + " - " + service.ImplementationType);
29-
}
30-
31-
var dest = mapper.Map<Dest2>(new Source2());
32-
Console.WriteLine(dest.ResolvedValue);
33-
}
34-
35-
Console.ReadKey();
36-
}
15+
Console.WriteLine($"{typeMap.SourceType.Name} -> {typeMap.DestinationType.Name}");
3716
}
3817

39-
public class Source
18+
foreach (var service in services)
4019
{
20+
Console.WriteLine(service.ServiceType + " - " + service.ImplementationType);
4121
}
4222

43-
public class Dest
44-
{
45-
}
23+
var dest = mapper.Map<Dest2>(new Source2());
24+
Console.WriteLine(dest.ResolvedValue);
25+
}
4626

47-
public class Source2
48-
{
49-
}
27+
Console.ReadKey();
5028

51-
public class Dest2
52-
{
53-
public int ResolvedValue { get; set; }
54-
}
29+
public class Source
30+
{
31+
}
5532

56-
public class Profile1 : Profile
57-
{
58-
public Profile1()
59-
{
60-
CreateMap<Source, Dest>();
61-
}
62-
}
33+
public class Dest
34+
{
35+
}
6336

64-
public class Profile2 : Profile
37+
public class Source2
38+
{
39+
}
40+
41+
public class Dest2
42+
{
43+
public int ResolvedValue { get; set; }
44+
}
45+
46+
public class Profile1 : Profile
47+
{
48+
public Profile1()
6549
{
66-
public Profile2()
67-
{
68-
CreateMap<Source2, Dest2>()
69-
.ForMember(d => d.ResolvedValue, opt => opt.MapFrom<DependencyResolver>());
70-
}
50+
CreateMap<Source, Dest>();
7151
}
52+
}
7253

73-
public class DependencyResolver : IValueResolver<object, object, int>
54+
public class Profile2 : Profile
55+
{
56+
public Profile2()
7457
{
75-
private readonly ISomeService _service;
58+
CreateMap<Source2, Dest2>()
59+
.ForMember(d => d.ResolvedValue, opt => opt.MapFrom<DependencyResolver>());
60+
}
61+
}
7662

77-
public DependencyResolver(ISomeService service)
78-
{
79-
_service = service;
80-
}
63+
public class DependencyResolver : IValueResolver<object, object, int>
64+
{
65+
private readonly ISomeService _service;
8166

82-
public int Resolve(object source, object destination, int destMember, ResolutionContext context)
83-
{
84-
return _service.Modify(destMember);
85-
}
67+
public DependencyResolver(ISomeService service)
68+
{
69+
_service = service;
8670
}
8771

88-
public interface ISomeService
72+
public int Resolve(object source, object destination, int destMember, ResolutionContext context)
8973
{
90-
int Modify(int value);
74+
return _service.Modify(destMember);
9175
}
76+
}
9277

93-
public class FooService : ISomeService
94-
{
95-
private readonly int _value;
78+
public interface ISomeService
79+
{
80+
int Modify(int value);
81+
}
9682

97-
public FooService(int value)
98-
{
99-
_value = value;
100-
}
83+
public class FooService : ISomeService
84+
{
85+
private readonly int _value;
10186

102-
public int Modify(int value) => value + _value;
87+
public FooService(int value)
88+
{
89+
_value = value;
10390
}
91+
92+
public int Modify(int value) => value + _value;
10493
}
94+

src/TestApp/TestApp.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<AssemblyName>TestApp</AssemblyName>
66
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
79
<PackageId>TestApp</PackageId>
810
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
911
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>

test/AutoMapper.Extensions.Microsoft.DependencyInjection.Tests/AutoMapper.Extensions.Microsoft.DependencyInjection.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net5.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0</TargetFrameworks>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>AutoMapper.Extensions.Microsoft.DependencyInjection.Tests</AssemblyName>
77
<PackageId>AutoMapper.Extensions.Microsoft.DependencyInjection.Tests</PackageId>

0 commit comments

Comments
 (0)