Skip to content
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

chore: Remove dependency of AWS.Lambda.Powertools.Common on all Utilities #340

Merged
merged 18 commits into from
Sep 13, 2023

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Jul 4, 2023

Please provide the issue number

Issue number: #339

Summary

Utilities have a dependency on the AWS.Lambda.Powertools.Common project.
When the utility is compiled and packaged into a nuget package the AWS.Lambda.Powertools.Common is a dependency.
This behaviour is causing Diamond dependency issues in the project.
To address this we should copy the required files to each utility and make them completely isolated. This allows the client to not have to worry about dependencies between utilities and AWS.Lambda.Powertools.Common.
There is no need to delete the AWS.Lambda.Powertools.Common project but link the files in other projects, this will make it more readable in the solution explorer and makes maintenance easier because it's all in a single project.

Changes

  • Remove dependency of AWS.Lambda.Powertools.Common project in all utilities
  • Create a Compile Include Link from AWS.Lambda.Powertools.Common files to all utilities csproj
    Pasted image 20230704131824
  • Add a reference to AspectInjector
    Pasted image 20230704115449
  • This will result in linked files in the Common folder of the utility project
    image

Updated test project dependencies to latest versions

Please provide a summary of what's being changed

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…ities.

Create a Compile Include Link from AWS.Lambda.Powertools.Common files to all utilities csproj. Add a reference to AspectInjector
@auto-assign auto-assign bot requested review from amirkaws and sliedig July 4, 2023 15:25
@boring-cyborg boring-cyborg bot added area/idempotency area/logging Core logging utility area/metrics Core metrics utility area/parameters area/tracing Core tracing utility tests labels Jul 4, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 4, 2023
Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
@hjgraca hjgraca changed the title chore: Remove dependency of Common in Utilities chore: Remove dependency of AWS.Lambda.Powertools.Common on all Utilities Jul 6, 2023
@github-actions github-actions bot added the internal Maintenance changes label Jul 6, 2023
@hjgraca hjgraca linked an issue Jul 6, 2023 that may be closed by this pull request
1 task
@hjgraca
Copy link
Contributor Author

hjgraca commented Jul 14, 2023

After some conversations with @amirkaws and his feedback, I have made some changes to the implementation.

TLDR:

  • Add Directory.Build.props and Directory.Build.targets more info
    • These two files allows us to modify all csproj files in the solution or where the files are placed in the folder structure
    • Those files were added to the src folder. They modify all csproj in that folder where all utilities are. Search scope
  • Add Central Package Management more info
    • Dependency management is a core feature of NuGet. Managing dependencies for a single project can be easy. Managing dependencies for multi-project solutions can prove to be difficult as they start to scale in size and complexity. In situations where you manage common dependencies for many different projects, you can leverage NuGet's central package management (CPM) features to do all of this from the ease of a single location.
    • Add a file Directory.Packages.props to the src and test folders. This allows us to manage nuget package versions for all projects in a central location. I separated src and tests because tests have many dependencies and can cause confusion. Search scope info

Implementation

Part 1 Directory.Build.props

  • Use MSbuild to:
    • Manage all common properties across all projects
    • These properties can be overridden by the project if it wishes to do so
      image

Part 2 Directory.Build.targets (changes only happen in Release configuration)

  • Use MSbuild to:
    • Copy/Link AWS.Lambda.Powertools.Common *.cs files to the destination project
    • Remove depdendency of Common project by removing <ProjectReference Remove="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" />
    • Add PackageReference <PackageReference Include="AspectInjector" />
  • This transformation only happens in Release configuration

image

Once in Release configuration or when running dotnet build -c Release the Common folder is added to the project

image

Part 3 Central Package Management

Docs

Starting with NuGet 6.2, you can centrally manage your dependencies in your projects with the addition of a Directory.Packages.props file and an MSBuild property.

This means that the versions of the referenced packages will be defined in the central Directory.Packages.props file

File contents:
image

In the csproj files of the projects the referenced packages will not have a version

image

If needed individual projects can override the version

Part 4 Nuget package contents

The resulting Release package will have no AWS.Lambda.Powertools.Common reference and will include AspectInjector nuget package. This will make the utility completely independent from AWS.Lambda.Powertools.Common Nuget package at runtime

Old:

image

New:

image

@boring-cyborg boring-cyborg bot added the area/common Core Powertools utility label Jul 14, 2023
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 14, 2023
@hjgraca
Copy link
Contributor Author

hjgraca commented Jul 14, 2023

Also updated nuget packages. Once merged will close dependabot pull requests.

@hjgraca hjgraca added the do-not-merge PRs that are blocked for varying reasons label Jul 14, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.09% ⚠️

Comparison is base (1378d75) 72.34% compared to head (d3505b5) 72.25%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #340      +/-   ##
===========================================
- Coverage    72.34%   72.25%   -0.09%     
===========================================
  Files           82       82              
  Lines         3594     3594              
===========================================
- Hits          2600     2597       -3     
- Misses         994      997       +3     
Flag Coverage Δ
unittests 72.25% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hjgraca
Copy link
Contributor Author

hjgraca commented Jul 20, 2023

Removed AWS.Lambda.Powertools.Common project reference from test projects.
This reference now comes from Directory.Build.props. This file was added to test folder.

Contents:
carbon (1)

@hjgraca hjgraca removed the do-not-merge PRs that are blocked for varying reasons label Jul 20, 2023
Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
Change Moq to NSubstitute
Update versions
Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
cant have version if using central repo
Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
@sonarcloud
Copy link

sonarcloud bot commented Sep 12, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@hjgraca hjgraca merged commit 77bae31 into aws-powertools:develop Sep 13, 2023
7 checks passed
@hjgraca hjgraca deleted the fix-common-dependency branch September 13, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/common Core Powertools utility area/idempotency area/logging Core logging utility area/metrics Core metrics utility area/parameters area/tracing Core tracing utility internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: Fix Common project dependency
3 participants