1717using NullGuard ;
1818using ReactiveUI ;
1919using Stateless ;
20+ using System . Collections . Specialized ;
2021
2122namespace GitHub . Controllers
2223{
@@ -36,6 +37,7 @@ enum Trigger { Cancel = 0, Auth = 1, Create = 2, Clone = 3, Publish = 4, Next, F
3637 readonly StateMachine < UIViewType , Trigger > machine ;
3738 Subject < UserControl > transition ;
3839 UIControllerFlow currentFlow ;
40+ NotifyCollectionChangedEventHandler connectionAdded ;
3941
4042 [ ImportingConstructor ]
4143 public UIController ( IUIProvider uiProvider , IRepositoryHosts hosts , IExportFactoryProvider factory ,
@@ -238,10 +240,11 @@ public void Start([AllowNull] IConnection connection)
238240 {
239241 if ( ! loggedin && currentFlow != UIControllerFlow . Authentication )
240242 {
241- connectionManager . Connections . CollectionChanged + = ( s , e ) => {
242- if ( e . Action == System . Collections . Specialized . NotifyCollectionChangedAction . Add )
243+ connectionAdded = ( s , e ) => {
244+ if ( e . Action == NotifyCollectionChangedAction . Add )
243245 uiProvider . AddService ( typeof ( IConnection ) , e . NewItems [ 0 ] ) ;
244246 } ;
247+ connectionManager . Connections . CollectionChanged += connectionAdded ;
245248 }
246249
247250 machine . Configure ( UIViewType . None )
@@ -278,6 +281,9 @@ protected virtual void Dispose(bool disposing)
278281 Debug . WriteLine ( "Disposing ({0})" , GetHashCode ( ) ) ;
279282 disposables . Dispose ( ) ;
280283 transition ? . Dispose ( ) ;
284+ if ( connectionAdded != null )
285+ connectionManager . Connections . CollectionChanged -= connectionAdded ;
286+ connectionAdded = null ;
281287 disposed = true ;
282288 }
283289 }
0 commit comments