Skip to content

Commit d0ed291

Browse files
authored
Merge pull request #4202 from AutoMapper/net6
Target .NET 6
2 parents 7229dd7 + 8e53710 commit d0ed291

32 files changed

+377
-132
lines changed

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ $artifacts = ".\artifacts"
2626

2727
if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }
2828

29-
exec { & dotnet test -c Release --results-directory $artifacts -l trx --verbosity=normal }
29+
exec { & dotnet test -c Release --results-directory $artifacts -l trx }
3030

3131
exec { & dotnet pack .\src\AutoMapper\AutoMapper.csproj -c Release -o $artifacts --no-build }

docs/13.0-Upgrade-Guide.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 13.0 Upgrade Guide
2+
3+
[Release notes](https://github.com/AutoMapper/AutoMapper/releases/tag/v13.0.0).
4+
5+
## AutoMapper now targets .Net 6
6+
7+
## `IMapper` has nullable annotations
8+
9+
Besides the build-time impact, there is also a behaviour change. Non-generic `Map` overloads require now either a destination type or a non-null destination object.
10+
11+
## `AllowAdditiveTypeMapCreation` was removed
12+
13+
Be sure to call `CreateMap` once for a source type, destination type pair. If you want to reuse configuration, use mapping inheritance.

docs/Configuration-validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var configuration = new MapperConfiguration(cfg =>
5050
);
5151
```
5252

53-
To skip validation altogether for this map, use `MemberList.None`.
53+
To skip validation altogether for this map, use `MemberList.None`. That's the default for `ReverseMap`.
5454

5555

5656
## Custom validations

docs/Queryable-Extensions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,15 @@ You may also use a dictionary to build the projection values:
208208
dbContext.Courses.ProjectTo<CourseModel>(Config, new Dictionary<string, object> { {"currentUserName", Request.User.Name} });
209209
```
210210

211-
However, using a dictionary will result in hard-coded values in the query instead of a parameterized query, so use with caution.
211+
However, using a dictionary will result in hard-coded values in the query instead of a parameterized query, so use with caution.
212+
213+
### Recursive models
214+
215+
Ideally, you would avoid models that reference themselves (do some research). But if you must, you need to enable them:
216+
217+
```c#
218+
configuration.Internal().RecursiveQueriesMaxDepth = someRandomNumber;
219+
```
212220

213221
### Supported mapping options
214222

docs/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ other simple objects, whose design is better suited for serialization,
1111
communication, messaging, or simply an anti-corruption layer between the
1212
domain and application layer.
1313

14-
AutoMapper supports the following platforms:
15-
16-
* `.NET Standard 2.1+ <https://docs.microsoft.com/en-us/dotnet/standard/net-standard>`_
17-
1814
New to AutoMapper? Check out the :doc:`Getting-started` page first.
1915

2016
.. _user-docs:

src/AutoMapper/ApiCompatBaseline.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Compat issues with assembly AutoMapper:
22
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.AutoMapAttribute' changed from '[AttributeUsageAttribute(1036, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, AllowMultiple=true)]' in the implementation.
3+
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.PropertyMapAction> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' is present in the implementation but not in the contract.
4+
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<System.Action<AutoMapper.PropertyMap, AutoMapper.IMemberConfigurationExpression>> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' is present in the contract but not in the implementation.
5+
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<System.Action<AutoMapper.PropertyMap, AutoMapper.IMemberConfigurationExpression>> AutoMapper.IProfileConfiguration.AllPropertyMapActions.get()' does not exist in the implementation but it does exist in the contract.
36
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.Configuration.ICtorParamConfigurationExpression.ExplicitExpansion()' is present in the implementation but not in the contract.
47
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.IgnoreAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
58
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.MapAtRuntimeAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
@@ -10,4 +13,4 @@ CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMappe
1013
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueConverterAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
1114
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueResolverAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
1215
TypeCannotChangeClassification : Type 'AutoMapper.Execution.TypeMapPlanBuilder' is a 'ref struct' in the implementation but is a 'struct' in the contract.
13-
Total Issues: 11
16+
Total Issues: 14

src/AutoMapper/AutoMapper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Summary>A convention-based object-object mapper.</Summary>
55
<Description>A convention-based object-object mapper.</Description>
6-
<TargetFrameworks>netstandard2.1</TargetFrameworks>
6+
<TargetFrameworks>net6.0</TargetFrameworks>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<AssemblyName>AutoMapper</AssemblyName>
99
<AssemblyOriginatorKeyFile>..\..\AutoMapper.snk</AssemblyOriginatorKeyFile>

src/AutoMapper/AutoMapperMappingException.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ public DuplicateTypeMapConfigurationException(TypeMapConfigErrors[] errors)
8181
{
8282
Errors = errors;
8383
var builder = new StringBuilder();
84-
builder.AppendLine("The following type maps were found in multiple profiles:");
84+
builder.AppendLine("Duplicate CreateMap calls:");
8585
foreach (var error in Errors)
8686
{
8787
builder.AppendLine($"{error.Types.SourceType.FullName} to {error.Types.DestinationType.FullName} defined in profiles:");
8888
builder.AppendLine(string.Join(Environment.NewLine, error.ProfileNames));
8989
}
90-
builder.AppendLine("This can cause configuration collisions and inconsistent mapping.");
91-
builder.AppendLine("Consolidate the CreateMap calls into one profile, or set the root Internal().AllowAdditiveTypeMapCreation configuration value to 'true'.");
92-
90+
builder.AppendLine("This can cause configuration collisions and inconsistent mappings. Use a single CreateMap call per type pair.");
9391
Message = builder.ToString();
9492
}
9593

src/AutoMapper/Configuration/ConfigurationValidator.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ private void Validate(ValidationContext context)
1313
}
1414
public void AssertConfigurationExpressionIsValid(IGlobalConfiguration config, IEnumerable<TypeMap> typeMaps)
1515
{
16-
if (!Expression.AllowAdditiveTypeMapCreation)
16+
var duplicateTypeMapConfigs = Expression.Profiles.Append((Profile)Expression)
17+
.SelectMany(p => p.TypeMapConfigs, (profile, typeMap) => (profile, typeMap))
18+
.GroupBy(x => x.typeMap.Types)
19+
.Where(g => g.Count() > 1)
20+
.Select(g => (TypePair : g.Key, ProfileNames : g.Select(tmc => tmc.profile.ProfileName).ToArray()))
21+
.Select(g => new DuplicateTypeMapConfigurationException.TypeMapConfigErrors(g.TypePair, g.ProfileNames))
22+
.ToArray();
23+
if (duplicateTypeMapConfigs.Any())
1724
{
18-
var duplicateTypeMapConfigs = Expression.Profiles.Append((Profile)Expression)
19-
.SelectMany(p => p.TypeMapConfigs, (profile, typeMap) => (profile, typeMap))
20-
.GroupBy(x => x.typeMap.Types)
21-
.Where(g => g.Count() > 1)
22-
.Select(g => (TypePair : g.Key, ProfileNames : g.Select(tmc => tmc.profile.ProfileName).ToArray()))
23-
.Select(g => new DuplicateTypeMapConfigurationException.TypeMapConfigErrors(g.TypePair, g.ProfileNames))
24-
.ToArray();
25-
if (duplicateTypeMapConfigs.Any())
26-
{
27-
throw new DuplicateTypeMapConfigurationException(duplicateTypeMapConfigs);
28-
}
25+
throw new DuplicateTypeMapConfigurationException(duplicateTypeMapConfigs);
2926
}
3027
AssertConfigurationIsValid(config, typeMaps);
3128
}

src/AutoMapper/Configuration/MapperConfigurationExpression.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ public class MapperConfigurationExpression : Profile, IGlobalConfigurationExpres
101101
/// <param name="validator">the validation callback</param>
102102
void IGlobalConfigurationExpression.Validator(Validator validator) =>
103103
_validators.Add(validator ?? throw new ArgumentNullException(nameof(validator)));
104-
105-
/// <summary>
106-
/// Allow the same map to exist in different profiles.
107-
/// The default is to throw an exception, true means the maps are merged.
108-
/// </summary>
109-
bool IGlobalConfigurationExpression.AllowAdditiveTypeMapCreation { get; set; }
110-
111104
/// <summary>
112105
/// How many levels deep should AutoMapper try to inline the execution plan for child classes.
113106
/// See <a href="https://automapper.readthedocs.io/en/latest/Understanding-your-mapping.html">the docs</a> for details.
@@ -184,7 +177,7 @@ private void AddMapsCore(IEnumerable<Assembly> assembliesToScan)
184177
{
185178
foreach (var memberConfigurationProvider in memberInfo.GetCustomAttributes().OfType<IMemberConfigurationProvider>())
186179
{
187-
mappingExpression.ForMember(memberInfo, cfg => memberConfigurationProvider.ApplyConfiguration(cfg));
180+
mappingExpression.ForMember(memberInfo, memberConfigurationProvider.ApplyConfiguration);
188181
}
189182
}
190183

@@ -195,5 +188,5 @@ private void AddMapsCore(IEnumerable<Assembly> assembliesToScan)
195188
AddProfile(autoMapAttributeProfile);
196189
}
197190

198-
public void ConstructServicesUsing(Func<Type, object> constructor) => _serviceCtor = constructor;
191+
public void ConstructServicesUsing(Func<Type, object> constructor) => _serviceCtor = constructor ?? throw new ArgumentNullException(nameof(constructor));
199192
}

0 commit comments

Comments
 (0)