aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2018-09-02 14:18:13 -0500
committerSean Hall <r.sean.hall@gmail.com>2018-09-02 14:18:13 -0500
commit2b41623f6d75acf6301f689db31570888c8abb3e (patch)
tree877363f1175b0570d16fe7df7232b3ae63e6db09 /src
parent23729f907e527bc2965b9ea1a80d3ab447c3b423 (diff)
downloadwix-2b41623f6d75acf6301f689db31570888c8abb3e.tar.gz
wix-2b41623f6d75acf6301f689db31570888c8abb3e.tar.bz2
wix-2b41623f6d75acf6301f689db31570888c8abb3e.zip
Use generics in WixToolsetServiceProvider
to make the compiler help with the type checking.
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Core/WixToolsetServiceProvider.cs57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs
index 9278ddc3..f4a9f78d 100644
--- a/src/WixToolset.Core/WixToolsetServiceProvider.cs
+++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs
@@ -14,34 +14,32 @@ namespace WixToolset.Core
14 { 14 {
15 public WixToolsetServiceProvider() 15 public WixToolsetServiceProvider()
16 { 16 {
17 this.CreationFunctions = new Dictionary<Type, Func<IServiceProvider, Dictionary<Type, object>, object>> 17 this.CreationFunctions = new Dictionary<Type, Func<IServiceProvider, Dictionary<Type, object>, object>>();
18 { 18 this.Singletons = new Dictionary<Type, object>();
19
19 // Singletons. 20 // Singletons.
20 { typeof(IExtensionManager), (provider, singletons) => AddSingleton(singletons, typeof(IExtensionManager), new ExtensionManager()) }, 21 this.AddService((provider, singletons) => AddSingleton<IExtensionManager>(singletons, new ExtensionManager()));
21 { typeof(IMessaging), (provider, singletons) => AddSingleton(singletons, typeof(IMessaging), new Messaging()) }, 22 this.AddService((provider, singletons) => AddSingleton<IMessaging>(singletons, new Messaging()));
22 { typeof(ITupleDefinitionCreator), (provider, singletons) => AddSingleton(singletons, typeof(ITupleDefinitionCreator), new TupleDefinitionCreator(provider)) }, 23 this.AddService((provider, singletons) => AddSingleton<ITupleDefinitionCreator>(singletons, new TupleDefinitionCreator(provider)));
23 { typeof(IParseHelper), (provider, singletons) => AddSingleton(singletons, typeof(IParseHelper), new ParseHelper(provider)) }, 24 this.AddService((provider, singletons) => AddSingleton<IParseHelper>(singletons, new ParseHelper(provider)));
24 { typeof(IPreprocessHelper), (provider, singletons) => AddSingleton(singletons, typeof(IPreprocessHelper), new PreprocessHelper(provider)) }, 25 this.AddService((provider, singletons) => AddSingleton<IPreprocessHelper>(singletons, new PreprocessHelper(provider)));
25 { typeof(IBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IBackendHelper), new BackendHelper(provider)) }, 26 this.AddService((provider, singletons) => AddSingleton<IBackendHelper>(singletons, new BackendHelper(provider)));
26 { typeof(IWindowsInstallerBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IWindowsInstallerBackendHelper), new WindowsInstallerBackendHelper(provider)) }, 27 this.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper(provider)));
27 28
28 // Transients. 29 // Transients.
29 { typeof(ICommandLineArguments), (provider, singletons) => new CommandLineArguments(provider) }, 30 this.AddService<ICommandLineArguments>((provider, singletons) => new CommandLineArguments(provider));
30 { typeof(ICommandLineContext), (provider, singletons) => new CommandLineContext(provider) }, 31 this.AddService<ICommandLineContext>((provider, singletons) => new CommandLineContext(provider));
31 { typeof(ICommandLineParser), (provider, singletons) => new CommandLineParser(provider) }, 32 this.AddService<ICommandLineParser>((provider, singletons) => new CommandLineParser(provider));
32 { typeof(IPreprocessContext), (provider, singletons) => new PreprocessContext(provider) }, 33 this.AddService<IPreprocessContext>((provider, singletons) => new PreprocessContext(provider));
33 { typeof(ICompileContext), (provider, singletons) => new CompileContext(provider) }, 34 this.AddService<ICompileContext>((provider, singletons) => new CompileContext(provider));
34 { typeof(ILinkContext), (provider, singletons) => new LinkContext(provider) }, 35 this.AddService<ILinkContext>((provider, singletons) => new LinkContext(provider));
35 { typeof(IResolveContext), (provider, singletons) => new ResolveContext(provider) }, 36 this.AddService<IResolveContext>((provider, singletons) => new ResolveContext(provider));
36 { typeof(IBindContext), (provider, singletons) => new BindContext(provider) }, 37 this.AddService<IBindContext>((provider, singletons) => new BindContext(provider));
37 { typeof(ILayoutContext), (provider, singletons) => new LayoutContext(provider) }, 38 this.AddService<ILayoutContext>((provider, singletons) => new LayoutContext(provider));
38 { typeof(IInscribeContext), (provider, singletons) => new InscribeContext(provider) }, 39 this.AddService<IInscribeContext>((provider, singletons) => new InscribeContext(provider));
39
40 // Internal implementations.
41 { typeof(ILocalizer), (provider, singletons) => new Localizer(provider) },
42 };
43 40
44 this.Singletons = new Dictionary<Type, object>(); 41 // Internal implementations.
42 this.AddService<ILocalizer>((provider, singletons) => new Localizer(provider));
45 } 43 }
46 44
47 private Dictionary<Type, Func<IServiceProvider, Dictionary<Type, object>, object>> CreationFunctions { get; } 45 private Dictionary<Type, Func<IServiceProvider, Dictionary<Type, object>, object>> CreationFunctions { get; }
@@ -80,9 +78,16 @@ namespace WixToolset.Core
80 this.CreationFunctions[serviceType] = creationFunction; 78 this.CreationFunctions[serviceType] = creationFunction;
81 } 79 }
82 80
83 private static object AddSingleton(Dictionary<Type, object> singletons, Type type, object service) 81 public void AddService<T>(Func<IServiceProvider, Dictionary<Type, object>, T> creationFunction)
82 where T : class
83 {
84 AddService(typeof(T), creationFunction);
85 }
86
87 private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service)
88 where T : class
84 { 89 {
85 singletons.Add(type, service); 90 singletons.Add(typeof(T), service);
86 return service; 91 return service;
87 } 92 }
88 } 93 }