@@ -30,9 +30,9 @@ public void GenerateHttpTriggerFunction()
30
30
Type = "HttpTrigger" ,
31
31
Name = inputBindingName
32
32
} ;
33
- var scriptHostInfo = GetScriptHostInfo ( ) ;
34
- MethodInfo method = GenerateMethod ( trigger , scriptHostInfo ) ;
35
33
34
+ MethodInfo method = GenerateMethod ( trigger ) ;
35
+
36
36
VerifyCommonProperties ( method ) ;
37
37
38
38
// verify trigger parameter
@@ -54,8 +54,8 @@ public void GenerateQueueTriggerFunction()
54
54
{ "direction" , "in" } ,
55
55
{ "queueName" , "test" }
56
56
} ) ;
57
- var scriptHostInfo = GetScriptHostInfo ( ) ;
58
- MethodInfo method = GenerateMethod ( trigger , scriptHostInfo ) ;
57
+
58
+ MethodInfo method = GenerateMethod ( trigger ) ;
59
59
60
60
VerifyCommonProperties ( method ) ;
61
61
@@ -86,12 +86,14 @@ public void GenerateQueueTriggerFunction_WithInvalidInputName_Fails()
86
86
{ "QueueName" , "test" }
87
87
} ;
88
88
89
- var scriptHostInfo = GetScriptHostInfo ( ) ;
90
- Exception ex = Assert . Throws < InvalidOperationException > ( ( ) => GenerateMethod ( trigger , scriptHostInfo ) ) ;
91
- Assert . Equal ( "Sequence contains no elements" , ex . Message ) ;
92
-
93
- var functionError = scriptHostInfo . Host . FunctionErrors [ FunctionName ] ;
94
- Assert . True ( functionError . Contains ( expectedError ) ) ;
89
+ using ( var scriptHostInfo = GetScriptHostInfo ( ) )
90
+ {
91
+ Exception ex = Assert . Throws < InvalidOperationException > ( ( ) => GenerateMethod ( trigger , scriptHostInfo ) ) ;
92
+ Assert . Equal ( "Sequence contains no elements" , ex . Message ) ;
93
+
94
+ var functionError = scriptHostInfo . Host . FunctionErrors [ FunctionName ] ;
95
+ Assert . True ( functionError . Contains ( expectedError ) ) ;
96
+ }
95
97
}
96
98
97
99
private static void VerifyCommonProperties ( MethodInfo method )
@@ -117,6 +119,14 @@ private static void VerifyCommonProperties(MethodInfo method)
117
119
Assert . Equal ( typeof ( ExecutionContext ) , parameter . ParameterType ) ;
118
120
}
119
121
122
+ private static MethodInfo GenerateMethod ( BindingMetadata trigger )
123
+ {
124
+ using ( var scriptHostInfo = GetScriptHostInfo ( ) )
125
+ {
126
+ return GenerateMethod ( trigger , scriptHostInfo ) ;
127
+ }
128
+ }
129
+
120
130
private static MethodInfo GenerateMethod ( BindingMetadata trigger , ScriptHostInfo scriptHostInfo )
121
131
{
122
132
FunctionMetadata metadata = new FunctionMetadata ( ) ;
@@ -146,18 +156,38 @@ private static ScriptHostInfo GetScriptHostInfo()
146
156
{
147
157
RootScriptPath = rootPath
148
158
} ;
149
- ScriptHost host = ScriptHost . Create ( scriptConfig ) ;
150
- return new ScriptHostInfo { Host = host , Configuration = scriptConfig , RootPath = rootPath } ;
159
+ var host = ScriptHost . Create ( scriptConfig ) ;
160
+ return new ScriptHostInfo ( host , scriptConfig , rootPath ) ;
151
161
}
152
162
}
153
163
154
164
[ SuppressMessage ( "Microsoft.StyleCop.CSharp.MaintainabilityRules" , "SA1402:FileMayOnlyContainASingleClass" ) ]
155
- internal class ScriptHostInfo
165
+ internal class ScriptHostInfo : IDisposable
156
166
{
157
- public ScriptHost Host { get ; set ; }
167
+ public ScriptHostInfo ( ScriptHost host , ScriptHostConfiguration config , string rootPath )
168
+ {
169
+ Host = host ;
170
+ Configuration = config ;
171
+ RootPath = rootPath ;
172
+ }
158
173
159
- public ScriptHostConfiguration Configuration { get ; set ; }
174
+ public ScriptHost Host { get ; }
160
175
161
- public string RootPath { get ; set ; }
176
+ public ScriptHostConfiguration Configuration { get ; }
177
+
178
+ public string RootPath { get ; }
179
+
180
+ protected virtual void Dispose ( bool disposing )
181
+ {
182
+ if ( disposing )
183
+ {
184
+ Host . Dispose ( ) ;
185
+ }
186
+ }
187
+
188
+ public void Dispose ( )
189
+ {
190
+ Dispose ( true ) ;
191
+ }
162
192
}
163
193
}
0 commit comments