This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
src/GitHub.VisualStudio/Services Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,12 @@ public class VSGitExtFactory
1818 {
1919 static readonly ILogger log = LogManager . ForContext < VSGitExtFactory > ( ) ;
2020
21- readonly IGitHubServiceProvider serviceProvider ;
22-
2321 [ ImportingConstructor ]
2422 public VSGitExtFactory ( IGitHubServiceProvider serviceProvider )
2523 {
26- this . serviceProvider = serviceProvider ;
24+ VSGitExt = serviceProvider . GetService < IVSGitExt > ( ) ;
2725 }
2826
29- [ Export ( typeof ( IVSGitExt ) ) ]
30- public IVSGitExt VSGitExt => serviceProvider . GetService < IVSGitExt > ( ) ;
31-
3227 public async static Task < IVSGitExt > Create ( IAsyncServiceProvider sp )
3328 {
3429 var dte = await sp . GetServiceAsync ( typeof ( DTE ) ) as DTE ;
@@ -37,13 +32,20 @@ public async static Task<IVSGitExt> Create(IAsyncServiceProvider sp)
3732 switch ( dte . Version )
3833 {
3934 case "14.0" :
40- return new Lazy < IVSGitExt > ( ( ) => new VSGitExt14 ( sp . GetServiceAsync ) ) . Value ;
35+ return Create ( ( ) => new VSGitExt14 ( sp . GetServiceAsync ) ) ;
4136 case "15.0" :
42- return new Lazy < IVSGitExt > ( ( ) => new VSGitExt15 ( sp . GetServiceAsync ) ) . Value ;
37+ return Create ( ( ) => new VSGitExt15 ( sp . GetServiceAsync ) ) ;
4338 default :
4439 log . Error ( "There is no IVSGitExt implementation for DTE version {Version}" , dte . Version ) ;
4540 return null ;
4641 }
4742 }
43+
44+ // NOTE: We're being careful to only reference VSGitExt14 and VSGitExt15 from inside a lambda expression.
45+ // This ensures that only the type that's compatible with the running DTE version is loaded.
46+ static IVSGitExt Create ( Func < IVSGitExt > factory ) => factory . Invoke ( ) ;
47+
48+ [ Export ]
49+ public IVSGitExt VSGitExt { get ; }
4850 }
4951}
You can’t perform that action at this time.
0 commit comments