55using LibGit2Sharp ;
66using Microsoft . VisualStudio ;
77using Microsoft . VisualStudio . ComponentModelHost ;
8- using Microsoft . VisualStudio . Shell ;
98using Microsoft . VisualStudio . Shell . Interop ;
109using GitHub . Info ;
1110using GitHub . Primitives ;
1211using GitHub . Extensions ;
1312
1413namespace GitHub . VisualStudio
1514{
15+
1616 public static class Services
1717 {
1818 public static IServiceProvider PackageServiceProvider { get ; set ; }
1919
2020 /// <summary>
21- /// Three ways of getting a service. First, trying the passed-in <paramref name="provider"/>,
22- /// then <see cref="PackageServiceProvider"/>, then <see cref="T:Microsoft.VisualStudio.Shell.Package"/>
23- /// If the passed-in provider returns null, try PackageServiceProvider or Package, returning the fetched value
24- /// regardless of whether it's null or not. Package.GetGlobalService is never called if PackageServiceProvider is set.
25- /// This is on purpose, to support easy unit testing outside VS.
21+ /// Two ways of getting a service. First, trying the passed-in <paramref name="provider"/>,
22+ /// then <see cref="PackageServiceProvider"/>
23+ /// If the passed-in provider returns null, try PackageServiceProvider, returning the fetched value
24+ /// regardless of whether it's null or not.
2625 /// </summary>
2726 /// <typeparam name="T"></typeparam>
2827 /// <typeparam name="Ret"></typeparam>
@@ -35,9 +34,7 @@ static Ret GetGlobalService<T, Ret>(IServiceProvider provider = null) where T :
3534 ret = provider . GetService ( typeof ( T ) ) as Ret ;
3635 if ( ret != null )
3736 return ret ;
38- if ( PackageServiceProvider != null )
39- return PackageServiceProvider . GetService ( typeof ( T ) ) as Ret ;
40- return Package . GetGlobalService ( typeof ( T ) ) as Ret ;
37+ return PackageServiceProvider . GetService ( typeof ( T ) ) as Ret ;
4138 }
4239
4340 public static IComponentModel ComponentModel
@@ -101,18 +98,6 @@ public static IVsSolution GetSolution(this IServiceProvider provider)
10198 return GetGlobalService < SVsSolution , IVsSolution > ( provider ) ;
10299 }
103100
104- public static T GetExportedValue < T > ( this IServiceProvider serviceProvider )
105- {
106- var ui = serviceProvider as IUIProvider ;
107- if ( ui != null )
108- return ui . GetService < T > ( ) ;
109- else
110- {
111- var componentModel = ( IComponentModel ) serviceProvider . GetService ( typeof ( SComponentModel ) ) ;
112- return componentModel . DefaultExportProvider . GetExportedValue < T > ( ) ;
113- }
114- }
115-
116101 public static UriString GetRepoUrlFromSolution ( IVsSolution solution )
117102 {
118103 string solutionDir , solutionFile , userFile ;
@@ -125,11 +110,11 @@ public static UriString GetRepoUrlFromSolution(IVsSolution solution)
125110 return null ;
126111 using ( var repo = new Repository ( repoPath ) )
127112 {
128- return repo . GetUri ( ) ;
113+ return GetUri ( repo ) ;
129114 }
130115 }
131116
132- public static Repository GetRepoFromSolution ( this IVsSolution solution )
117+ public static IRepository GetRepoFromSolution ( this IVsSolution solution )
133118 {
134119 string solutionDir , solutionFile , userFile ;
135120 if ( ! ErrorHandler . Succeeded ( solution . GetSolutionInfo ( out solutionDir , out solutionFile , out userFile ) ) )
@@ -141,5 +126,10 @@ public static Repository GetRepoFromSolution(this IVsSolution solution)
141126 return null ;
142127 return new Repository ( repoPath ) ;
143128 }
129+ static UriString GetUri ( IRepository repo )
130+ {
131+ return UriString . ToUriString ( GitService . GetUriFromRepository ( repo ) ? . ToRepositoryUrl ( ) ) ;
132+ }
133+ public static IGitService IGitService { get { return PackageServiceProvider . GetService < IGitService > ( ) ; } }
144134 }
145135}
0 commit comments