-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathServiceOverrides.cs
More file actions
147 lines (123 loc) · 4.21 KB
/
ServiceOverrides.cs
File metadata and controls
147 lines (123 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Linq;
using ScriptCs.Contracts;
namespace ScriptCs.Hosting
{
public abstract class ServiceOverrides<TConfig> : IServiceOverrides<TConfig>
where TConfig : class, IServiceOverrides<TConfig>
{
public IDictionary<Type, object> Overrides { get; private set; }
private readonly TConfig _this;
protected ServiceOverrides()
{
_this = this as TConfig;
Overrides = new Dictionary<Type, object>();
}
protected ServiceOverrides(IDictionary<Type, object> overrides)
: this()
{
Overrides = overrides;
}
public TConfig ScriptHostFactory<T>() where T : IScriptHostFactory
{
Overrides[typeof(IScriptHostFactory)] = typeof(T);
return _this;
}
public TConfig ScriptExecutor<T>() where T : IScriptExecutor
{
Overrides[typeof(IScriptExecutor)] = typeof(T);
return _this;
}
public TConfig Repl<T>() where T : IRepl
{
Overrides[typeof(IRepl)] = typeof(T);
return _this;
}
public TConfig ScriptEngine<T>() where T : IScriptEngine
{
Overrides[typeof(IScriptEngine)] = typeof(T);
return _this;
}
public TConfig ScriptPackManager<T>() where T : IScriptPackManager
{
Overrides[typeof(IScriptPackManager)] = typeof(T);
return _this;
}
public TConfig ScriptPackResolver<T>() where T : IScriptPackResolver
{
Overrides[typeof(IScriptPackResolver)] = typeof(T);
return _this;
}
public TConfig InstallationProvider<T>() where T : IInstallationProvider
{
Overrides[typeof(IInstallationProvider)] = typeof(T);
return _this;
}
public TConfig FileSystem<T>() where T : IFileSystem
{
Overrides[typeof(IFileSystem)] = typeof(T);
return _this;
}
public TConfig AssemblyUtility<T>() where T : IAssemblyUtility
{
Overrides[typeof(IAssemblyUtility)] = typeof(T);
return _this;
}
public TConfig ObjectSerializer<T>() where T : IObjectSerializer
{
Overrides[typeof(IObjectSerializer)] = typeof(T);
return _this;
}
public TConfig PackageContainer<T>() where T : IPackageContainer
{
Overrides[typeof(IPackageContainer)] = typeof(T);
return _this;
}
public TConfig PackageInstaller<T>() where T : IPackageInstaller
{
Overrides[typeof(IPackageInstaller)] = typeof(T);
return _this;
}
public TConfig FilePreProcessor<T>() where T : IFilePreProcessor
{
Overrides[typeof(IFilePreProcessor)] = typeof(T);
return _this;
}
public TConfig PackageAssemblyResolver<T>() where T : IPackageAssemblyResolver
{
Overrides[typeof(IPackageAssemblyResolver)] = typeof(T);
return _this;
}
public TConfig AssemblyResolver<T>() where T : IAssemblyResolver
{
Overrides[typeof(IAssemblyResolver)] = typeof(T);
return _this;
}
public TConfig Console<T>() where T : IConsole
{
Overrides[typeof(IConsole)] = typeof(T);
return _this;
}
public TConfig LineProcessor<T>() where T : ILineProcessor
{
var key = typeof(ILineProcessor);
object value;
if (!Overrides.TryGetValue(key, out value) || value == null)
{
value = Enumerable.Empty<Type>();
}
IEnumerable<Type> processors;
try
{
processors = (IEnumerable<Type>)value;
}
catch (InvalidCastException ex)
{
throw new InvalidOperationException("The line processors override has an invalid type.", ex);
}
Overrides[typeof(ILineProcessor)] = new[] { typeof(T) }.Concat(processors).ToList();
return _this;
}
}
}