@@ -25,13 +25,13 @@ namespace AWS.Lambda.Powertools.Metrics;
2525/// Implements the <see cref="IMetrics" />
2626/// </summary>
2727/// <seealso cref="IMetrics" />
28- public class Metrics : IMetrics
28+ public class Metrics : IMetrics , IDisposable
2929{
3030 /// <summary>
3131 /// The instance
3232 /// </summary>
3333 private static IMetrics _instance ;
34-
34+
3535 /// <summary>
3636 /// The context
3737 /// </summary>
@@ -177,19 +177,19 @@ void IMetrics.AddMetadata(string key, object value)
177177 /// <summary>
178178 /// Implements interface that sets default dimension list
179179 /// </summary>
180- /// <param name="defaultDimensions ">Default Dimension List</param>
180+ /// <param name="defaultDimension ">Default Dimension List</param>
181181 /// <exception cref="System.ArgumentNullException">
182182 /// 'SetDefaultDimensions' method requires a valid key pair. 'Null' or empty
183183 /// values are not allowed.
184184 /// </exception>
185- void IMetrics . SetDefaultDimensions ( Dictionary < string , string > defaultDimensions )
185+ void IMetrics . SetDefaultDimensions ( Dictionary < string , string > defaultDimension )
186186 {
187- foreach ( var item in defaultDimensions )
187+ foreach ( var item in defaultDimension )
188188 if ( string . IsNullOrWhiteSpace ( item . Key ) || string . IsNullOrWhiteSpace ( item . Value ) )
189189 throw new ArgumentNullException (
190190 $ "'SetDefaultDimensions' method requires a valid key pair. 'Null' or empty values are not allowed.") ;
191191
192- _context . SetDefaultDimensions ( DictionaryToList ( defaultDimensions ) ) ;
192+ _context . SetDefaultDimensions ( DictionaryToList ( defaultDimension ) ) ;
193193 }
194194
195195 /// <summary>
@@ -272,7 +272,21 @@ void IMetrics.PushSingleMetric(string metricName, double value, MetricUnit unit,
272272 /// </summary>
273273 public void Dispose ( )
274274 {
275- _instance . Flush ( ) ;
275+ Dispose ( true ) ;
276+ GC . SuppressFinalize ( this ) ;
277+ }
278+
279+ /// <summary>
280+ ///
281+ /// </summary>
282+ /// <param name="disposing"></param>
283+ protected virtual void Dispose ( bool disposing )
284+ {
285+ // Cleanup
286+ if ( disposing )
287+ {
288+ _instance . Flush ( ) ;
289+ }
276290 }
277291
278292 /// <summary>
0 commit comments