Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 88109fb

Browse files
jcansdaleStanleyGoldman
authored andcommitted
Factor out GetExportProvider
1 parent d86fad5 commit 88109fb

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/GitHub.VisualStudio.16/Sync/PublishSection.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using Microsoft.VisualStudio.Threading;
1919
using ReactiveUI;
2020
using Task = System.Threading.Tasks.Task;
21+
using Microsoft.VisualStudio.Shell;
22+
using System.ComponentModel.Composition.Hosting;
2123

2224
namespace Microsoft.TeamExplorerSample.Sync
2325
{
@@ -80,27 +82,15 @@ public override void Initialize(object sender, SectionInitializeEventArgs e)
8082
}
8183
}
8284

83-
PublishToGitHub = new RelayCommand(o => DoPublishToGitHub().Forget());
85+
PublishToGitHub = new RelayCommand(o => ShowPublishDialog());
8486
}
8587

86-
async Task DoPublishToGitHub()
88+
void ShowPublishDialog()
8789
{
88-
var componentModel = ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
89-
ShowPublishDialog(componentModel);
90-
}
91-
92-
void ShowPublishDialog(IComponentModel componentModel)
93-
{
94-
/*
95-
var factory = ServiceProvider.GetService<IViewViewModelFactory>();
96-
var viewModel = ServiceProvider.GetService<IRepositoryPublishViewModel>();
97-
*/
90+
var exportProvide = GetExportProvider();
9891

99-
var compositionServices = new CompositionServices();
100-
var compositionContainer = compositionServices.CreateVisualStudioCompositionContainer(componentModel.DefaultExportProvider);
101-
102-
var factory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
103-
var viewModel = compositionContainer.GetExportedValue<IRepositoryPublishViewModel>();
92+
var factory = exportProvide.GetExportedValue<IViewViewModelFactory>();
93+
var viewModel = exportProvide.GetExportedValue<IRepositoryPublishViewModel>();
10494

10595
var busy = viewModel.WhenAnyValue(x => x.IsBusy).Subscribe(x => IsBusy = x);
10696

@@ -138,6 +128,15 @@ void ShowPublishDialog(IComponentModel componentModel)
138128
*/
139129
}
140130

131+
ExportProvider GetExportProvider()
132+
{
133+
var componentModel = ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
134+
Assumes.Present(componentModel);
135+
var compositionServices = new CompositionServices();
136+
var compositionContainer = compositionServices.CreateVisualStudioCompositionContainer(componentModel.DefaultExportProvider);
137+
return compositionContainer;
138+
}
139+
141140
void HandleCreatedRepo(LocalRepositoryModel newrepo)
142141
{
143142
var msg = String.Format(CultureInfo.CurrentCulture, Constants.Notification_RepoCreated, newrepo.Name, newrepo.CloneUrl);

0 commit comments

Comments
 (0)