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

WPF Refactoring #1: Add abstraction layer for MEF #3257

Merged
merged 10 commits into from
Aug 20, 2024

Conversation

tom-englert
Copy link
Contributor

Problem

The WPF-UI implementation is very inconsistent, e.g. often favoring the UI-first anti-pattern, with parts of the logic implemented in the UI instead of the view model.

Solution

I'd like to contribute iterative cleanup of some of the UI, starting with this PR that adds an abstraction layer to MEF, so DI can be used without a hard coded dependency to the container implementation.
This will allow to use existing tooling and maybe later update the container to some more modern implementation (e.g .Microsoft.Extensions.DependencyInjection)

Please leave some feedback here if such a cleanup is appreciated.

@siegfriedpammer
Copy link
Member

I appreciate your support.

Given that most parts of the UI are 13 years old and were hacked together on a weekend, I don't see a problem with the UI-first approach.

However, I agree that it's time to clean it up. I am really looking forward to having proper DI instead of static state everywhere.

@christophwille what do you think?

@christophwille
Copy link
Member

We looked at cleaning up the non-decompiler parts (UI) on and off over the years, and only ever managed to do minor improvements. Help definitely welcome especially around standardizing approaches, modern best practices (MEF, DI).

@tom-englert
Copy link
Contributor Author

OK, I'll do some review then and now, and try to provide step by step PR's, so it's trackable what has been changed.

  • What about naming conventions, formatting and use of newer language features? I it OK to normalize/update this in the touched files?
  • INotifyPropertyChanged implementation is duplicated everywhere, would using AOP (https://github.com/Fody/PropertyChanged) be an option?
  • Should we create an issue or discussion as a central hook for the PRs?

@christophwille
Copy link
Member

Fody is not an option.

All net80 targets can use latest language features, all I know is that primary ctors are a touchy subject (like please don't use those).

@siegfriedpammer
Copy link
Member

What about naming conventions, formatting and use of newer language features? I it OK to normalize/update this in the touched files?

  • Naming convention is the usual .NET naming convention except that fields do not use any kind of prefix
  • Use of newer language features: In general all language features can and should be used, however there are some exceptions:
    • primary constructors should only be used, if there is exactly one - the primary - constructor
    • file-scoped namespace declarations should not be applied to existing files - unless it's a refactoring that is applied to all files and the changes are all in one commit, which is then added to .git-blame-ignore-revs

@christophwille
Copy link
Member

INPC - if base classes don't cut it, one of the current and active source generators? @siegfriedpammer or would that be a no-go?

@siegfriedpammer
Copy link
Member

source generators are fine!

@christophwille
Copy link
Member

  • Should we create an issue or discussion as a central hook for the PRs?

If you already have a plan, surely a good idea.

@tom-englert tom-englert force-pushed the dev/WpfRefactoring branch 2 times, most recently from a73c09e to 2748c91 Compare August 13, 2024 11:13
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="TomsToolbox.Composition.Analyzer" Version="2.18.1" />
Copy link
Member

Choose a reason for hiding this comment

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

Is that really a good idea? That will then be applied to all the VSIX projects, ilspycmd, the installer, et cetera. We have fewer MEF projects than non-MEF projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GlobalPackageReferences are compile-time only by default, and this is just an analyzer helping to make consistent export definitions.

@tom-englert tom-englert marked this pull request as ready for review August 15, 2024 15:33
@christophwille
Copy link
Member

@tom-englert please let us know when you consider this "first refactoring" ready for review / merge

@tom-englert
Copy link
Contributor Author

@christophwille this is a first consistent step and ready for review

@@ -22,12 +22,15 @@

namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
using System.ComponentModel.Composition;
Copy link
Member

Choose a reason for hiding this comment

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

This should be moved out of the namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@siegfriedpammer
Copy link
Member

May I ask you to clean your commits up before we merge this once you are done? For example 4a933f6 and 22ad795 could be merged into one commit so that the file you added and then removed, never is visible in the commit history...

Thank you very much for helping us with the UI clean up! I really appreciate it!

@tom-englert
Copy link
Contributor Author

@siegfriedpammer OK, I'll ping you when I completed this.

@tom-englert
Copy link
Contributor Author

@siegfriedpammer History is now cleaned up

using System.Diagnostics;

using ICSharpCode.Decompiler.TypeSystem;
Copy link
Member

Choose a reason for hiding this comment

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

Ah cool, because this class was moved to ILSpyX, which does not reference WPF, we no longer have to deal with the "Accessibility.dll/namespace ambiguity" 👍

Copy link
Member

Choose a reason for hiding this comment

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

Can we please keep third-party-tooling-specific files out of the repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this would make the life harder for anyone using ReSharper, getting false positive warnings everywhere, making it impossible to write compliant code.
Is this what you want?

Copy link
Member

Choose a reason for hiding this comment

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

"make the life harder for anyone using X" where do we draw the line then on which tool is important enough for its custom configuration to go into the repo? Nobody in 10+ years ever asked for R#.

Copy link
Member

Choose a reason for hiding this comment

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

If you simply keep a copy for yourself and assume it unchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the missing rules to .editorconfig, so that's available to everybody now, independent of the tooling

Copy link
Contributor

Choose a reason for hiding this comment

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

Nobody in 10+ years ever asked for R#.

That's because they all use Rider now 😅

On a more serious note, I'd like to vote for being as friendly as possible towards R#/Rider users. Almost everyone at my work prefers Rider over VS, and no one uses plain VS without R# anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ltrzesniewski works now with .editorconfig instead of R#.settings, so that should be fine with Rider, too

Copy link
Member

Choose a reason for hiding this comment

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

Nobody in 10+ years ever asked for R#.

That's because they all use Rider now 😅

On a more serious note, I'd like to vote for being as friendly as possible towards R#/Rider users. Almost everyone at my work prefers Rider over VS, and no one uses plain VS without R# anymore.

and nobody on the core team uses anything besides VS...

@siegfriedpammer siegfriedpammer merged commit 58bd499 into icsharpcode:master Aug 20, 2024
5 checks passed
@siegfriedpammer
Copy link
Member

Thank you very much for the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants