-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Dependency injection #11142
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
Dependency injection #11142
Conversation
42ab47f
to
bf88dfa
Compare
bf88dfa
to
8d78eed
Compare
e28381b
to
aae8ef3
Compare
3a4edff
to
6f881e8
Compare
6f881e8
to
7363e9d
Compare
1555c29
to
fa71764
Compare
I'd like to have this merged. If no objections/feedback received, I'll merge this by the end of the week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work. I do not have principle objections.
The review of the first commit and of Program.cs
have raised questions which should be clarified before the complete review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the benefit is with the change.
But I trust the change and have no objections to merge.
Have only review by "pattern matching", i.e. uniform changes. Not run
This is the first step to using dependency injection throughout the application - i.e., avoid newing up instances inplace, and rather create a dependency tree upfront. This will have perf benefits and will make testing much easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the liberty to fix some comments myself. Could do for ScriptOptionsParser, too.
What do you think about the strict compostion in 09d143c?
I think it is clearer without loss of convenience.
IntegrationTests/UI.IntegrationTests/Script/ScriptRunnerTests.cs
Outdated
Show resolved
Hide resolved
0a02a1b
to
15f19ec
Compare
I've gone through several iterations of the API, and I didn't want to expose the SP publicly. To me it feels like an implementation detail which would unnecessarily burden the API surface. That said, I don't consider the API locked, and it's possible/likely a number of API will change as we utilise the DI more. |
15f19ec
to
d31ae17
Compare
The SP interface is publicly exposed by Public inheritance / interface implementation reads as "UICommands is a/the SP". UICommands is not the SP in the strict sense, it just holds it and makes it accessible. (Since |
f5ffdb9
to
9078788
Compare
9078788
to
7ecedd9
Compare
I started with passing Exposing I dislike the current implementation with the inheritance and (re-)assignment of |
0c81f0a
to
89b620e
Compare
serviceContainer.AddService(Substitute.For<IAppTitleGenerator>()); | ||
serviceContainer.AddService(Substitute.For<IWindowsJumpListManager>()); | ||
serviceContainer.AddService(Substitute.For<ResourceManager.ILinkFactory>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this works without specifying the interface type .AddService<IType>(...)
.
GitUI/GitUICommands.cs
Outdated
/// Creates a new instance of <see cref="GitUICommands"/> for a git repository specified by <paramref name="module"/>. | ||
/// Creates a new instance of <see cref="GitUICommands"/> for a git repository specified by <paramref name="module"/>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this on purpose. The double space makes it easier to read comments. We use this convention in a few .NET repos, notably in dotnet/winforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double space makes it easier to read comments.
This is pretty new - and done inconsistently in this PR (at least in Plugins/GitUIPluginInterfaces/ServiceProviderExtensions.cs
). I do not have strong opinion on it.
GitUI/CommitInfo/CommitInfo.cs
Outdated
return _commitDataBodyRenderer?.Render(data, showRevisionsAsLinks: false) ?? string.Empty; | ||
return _commitDataBodyRenderer.Render(data, showRevisionsAsLinks: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% convinced that this is safe. The data loading in this control is async, and without any cancelations. So, it's quite possible to get in a state where data is being loaded, and at the same time a repo is being unloaded which sets these variables to null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I stopped in the middle of a right movement.
@@ -420,11 +427,9 @@ async Task LoadLinksForRevisionAsync(GitRevision revision, DistributedSettings s | |||
|
|||
string GetLinksForRevision(DistributedSettings settings) | |||
{ | |||
IEnumerable<ExternalLink> links = _gitRevisionExternalLinksParser.Parse(revision, settings); | |||
cancellationToken.ThrowIfCancellationRequested(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved down on purpose because the caller has checked for cancellation right before calling this function.
0b48cb5
to
3d98756
Compare
Thank you for the reviews |
Proposed changes
Introduce the concept of a service container, which gets initialised at the very start of the app.
IGitUICommands
implementsIServiceProvider
, which means the service container is available anywhere where an instance of GitUICommands is.The service container is plumbed in, and MEF removed. However, nothing else has changed at this stage, and further enhancements will be coming as follow up work.
Merge strategy
❗ Don't squash.
✒️ I contribute this code under The Developer Certificate of Origin.