Skip to content

Update AutoMapper to 6.0.2 #4679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 26, 2017
Merged

Conversation

cormacpayne
Copy link
Member

@cormacpayne cormacpayne commented Sep 28, 2017

Description

Initial attempt at fixing issue #4294 by bumping the version of AutoMapper used and adopting a singleton pattern with the new version that will prevent the mapper from being populated every time a cmdlet is executed.


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@cormacpayne
Copy link
Member Author

Building packages job: http://azuresdkci.cloudapp.net/job/posh-pack/3/

Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of questiosn about AutoMapper.Net4 - it looks liek this was removed form the wxi file everywhere, but noted at least one palce there is still a reference. Want to make sure we understand why.

@@ -132,9 +132,6 @@
<Component Id="cmpBEA6E3263480C18705DC2E3B15E3C1CF" Guid="*">
<File Id="fil7E95F218EFC39408F9F2DB3FD01A124C" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.ApiManagement\AutoMapper.dll" />
</Component>
<Component Id="cmp957D146263F021CE3EF1CBADBF06D2C4" Guid="*">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't need this file anymore?

</Reference>
<Reference Include="AutoMapper.Net4, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\AutoMapper.3.1.1\lib\net40\AutoMapper.Net4.dll</HintPath>
<Reference Include="AutoMapper.Net4, Version=6.0.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like AutoMapper.Net4 is still used in some circumstances

@markcowl markcowl changed the base branch from preview to release-4.4.1 October 7, 2017 23:53
@blueww
Copy link
Member

blueww commented Oct 9, 2017

@cormacpayne
I don't see the storage module code change in this PR (am I missing anything?)
And I don't quite understand how the fix works.
Could you please give more details on how the problem happens, and how the fix works?
Thanks!

@cormacpayne
Copy link
Member Author

@blueww Hey Wei, the bulk of the Storage code changed is in the ServiceManagementProfile class, which defines the mappings for types used in RDFE cmdlets. It appears the issue that the user is seeing in #4418 comes from the code here - AutoMapper is trying to map an object of type StorageAccountGetResponse to StorageServicePropertiesOperationContext, but it cannot find a corresponding mapping (even though it's defined in the ServiceManagementProfile class).

Currently, AutoMapper is being used statically throughout the modules, which is why we believe these issues with "unsupported mappings" are popping up - the correct mappings may not have been instantiated by the time the mapper is used. This PR updates the version of AutoMapper used to 6.0.2, which deprecates the support of a static mapper, and we define a specific mapper to be used for each module. This ensures that every module has their own mapper, every call to Mapper.Map<Foo, Bar>() is using the module's specific mapper, and that the mapper is instantiated with the correct mappings whenever it is used.

Now, rather than calling Mapper.Map<Foo,Bar>() in the previously cited GetAzureStorageAccount class, you will now use the specific mapper that has defined the mappings you will need, ServiceManagementProfile.Mapper.Map<Foo,Bar>().

…hell into automapper-fix

# Conflicts:
#	src/ResourceManager/Compute/Commands.Compute/Generated/Models/ComputeAutoMapperProfile.cs
@cormacpayne
Copy link
Member Author

…hell into automapper-fix

# Conflicts:
#	src/ResourceManager/Network/Commands.Network/RouteTable/NewAzureRouteTableCommand.cs
#	src/ResourceManager/Network/Commands.Network/RouteTable/RouteTableBaseCmdlet.cs
#	src/ResourceManager/Network/Commands.Network/RouteTable/SetAzureRouteTableCommand.cs
@cormacpayne
Copy link
Member Author

@cormacpayne
Copy link
Member Author

@azuresdkci test this please

@cormacpayne cormacpayne changed the base branch from release-4.4.1 to preview October 16, 2017 17:10
@cormacpayne
Copy link
Member Author

@azuresdkci test this please

@markcowl markcowl assigned hyonholee and unassigned markcowl Oct 23, 2017
…nto automapper-fix

# Conflicts:
#	src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs
@maddieclayton maddieclayton dismissed markcowl’s stale review October 26, 2017 18:04

Approved offline pending compute signoff

@cormacpayne
Copy link
Member Author

Received sign-off from Compute and Network that this does not break existing scenarios.

@cormacpayne cormacpayne merged commit 5439f89 into Azure:preview Oct 26, 2017
@cormacpayne cormacpayne deleted the automapper-fix branch November 9, 2017 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants