1- using System ;
1+ extern alias TF14 ;
2+ extern alias TF15 ;
3+
4+ using System ;
25using System . ComponentModel . Composition ;
36using System . Diagnostics ;
47using System . Reflection ;
2225using Octokit ;
2326using Serilog ;
2427using Task = System . Threading . Tasks . Task ;
28+ using VSGitExt14 = TF14 . GitHub . VisualStudio . Base . VSGitExt ;
29+ using VSGitExt15 = TF15 . GitHub . VisualStudio . Base . VSGitExt ;
2530
2631namespace GitHub . VisualStudio
2732{
@@ -107,12 +112,28 @@ public GHClient(IProgram program)
107112 }
108113 }
109114
115+ [ PartCreationPolicy ( CreationPolicy . Shared ) ]
116+ public class VSGitExtPart
117+ {
118+ readonly IGitHubServiceProvider serviceProvider ;
119+
120+ [ ImportingConstructor ]
121+ public VSGitExtPart ( IGitHubServiceProvider serviceProvider )
122+ {
123+ this . serviceProvider = serviceProvider ;
124+ }
125+
126+ [ Export ( typeof ( IVSGitExt ) ) ]
127+ public IVSGitExt VSGitExt => serviceProvider . GetService < IVSGitExt > ( ) ;
128+ }
129+
110130 [ PackageRegistration ( UseManagedResourcesOnly = true , AllowsBackgroundLoading = true ) ]
111131 [ ProvideService ( typeof ( ILoginManager ) , IsAsyncQueryable = true ) ]
112132 [ ProvideService ( typeof ( IMenuProvider ) , IsAsyncQueryable = true ) ]
113133 [ ProvideService ( typeof ( IGitHubServiceProvider ) , IsAsyncQueryable = true ) ]
114134 [ ProvideService ( typeof ( IUsageTracker ) , IsAsyncQueryable = true ) ]
115135 [ ProvideService ( typeof ( IUsageService ) , IsAsyncQueryable = true ) ]
136+ [ ProvideService ( typeof ( IVSGitExt ) , IsAsyncQueryable = true ) ]
116137 [ ProvideService ( typeof ( IGitHubToolWindowManager ) ) ]
117138 [ Guid ( ServiceProviderPackageId ) ]
118139 public sealed class ServiceProviderPackage : AsyncPackage , IServiceProviderPackage , IGitHubToolWindowManager
@@ -150,6 +171,7 @@ Version VSVersion
150171 protected override Task InitializeAsync ( CancellationToken cancellationToken , IProgress < ServiceProgressData > progress )
151172 {
152173 AddService ( typeof ( IGitHubServiceProvider ) , CreateService , true ) ;
174+ AddService ( typeof ( IVSGitExt ) , CreateService , true ) ;
153175 AddService ( typeof ( IUsageTracker ) , CreateService , true ) ;
154176 AddService ( typeof ( IUsageService ) , CreateService , true ) ;
155177 AddService ( typeof ( ILoginManager ) , CreateService , true ) ;
@@ -258,6 +280,11 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
258280 var serviceProvider = await GetServiceAsync ( typeof ( IGitHubServiceProvider ) ) as IGitHubServiceProvider ;
259281 return new UsageTracker ( serviceProvider , usageService ) ;
260282 }
283+ else if ( serviceType == typeof ( IVSGitExt ) )
284+ {
285+ var sp = await GetServiceAsync ( typeof ( IGitHubServiceProvider ) ) as IGitHubServiceProvider ;
286+ return CreateVSGitExt ( sp ) ;
287+ }
261288 else if ( serviceType == typeof ( IGitHubToolWindowManager ) )
262289 {
263290 return this ;
@@ -269,5 +296,18 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
269296 return sp . TryGetService ( serviceType ) ;
270297 }
271298 }
299+
300+ IVSGitExt CreateVSGitExt ( IGitHubServiceProvider sp )
301+ {
302+ switch ( VSVersion . Major )
303+ {
304+ case 14 :
305+ return new Lazy < IVSGitExt > ( ( ) => new VSGitExt14 ( sp ) ) . Value ;
306+ case 15 :
307+ return new Lazy < IVSGitExt > ( ( ) => new VSGitExt15 ( sp ) ) . Value ;
308+ default :
309+ return null ;
310+ }
311+ }
272312 }
273313}
0 commit comments