public IDisposable ServiceRegistrationCallback(Type serviceType, string contract, Action <IDisposable> callback) { var pair = Tuple.Create(serviceType, contract ?? string.Empty); if (!_callbackRegistry.ContainsKey(pair)) { _callbackRegistry[pair] = new List <Action <IDisposable> >(); } _callbackRegistry[pair].Add(callback); var disp = new ActionDisposable(() => { _callbackRegistry[pair].Remove(callback); }); if (_registry.ContainsKey(pair)) { foreach (var s in _registry[pair]) { callback(disp); } } return(disp); }
public void Register(Func <object> factory, Type serviceType, string contract = null) { if (this.innerRegister == null) { throw new NotImplementedException(); } this.innerRegister(factory, serviceType, contract); Tuple <Type, string> key = Tuple.Create <Type, string>(serviceType, contract ?? string.Empty); if (this._callbackRegistry.ContainsKey(key)) { List <Action <IDisposable> > list = null; foreach (Action <IDisposable> action in this._callbackRegistry[key]) { bool remove = false; ActionDisposable disposable = new ActionDisposable(() => remove = true); action(disposable); if (remove) { if (list == null) { list = new List <Action <IDisposable> >(); } list.Add(action); } } if (list != null) { foreach (Action <IDisposable> action2 in list) { this._callbackRegistry[key].Remove(action2); } } } }
public void Register(Func <object> factory, Type serviceType, string contract = null) { var pair = Tuple.Create(serviceType, contract ?? string.Empty); if (!_registry.ContainsKey(pair)) { _registry[pair] = new List <Func <object> >(); } _registry[pair].Add(factory); if (_callbackRegistry.ContainsKey(pair)) { List <Action <IDisposable> > toRemove = null; foreach (var callback in _callbackRegistry[pair]) { var remove = false; var disp = new ActionDisposable(() => { remove = true; }); callback(disp); if (remove) { if (toRemove == null) { toRemove = new List <Action <IDisposable> >(); } toRemove.Add(callback); } } if (toRemove != null) { foreach (var c in toRemove) { _callbackRegistry[pair].Remove(c); } } } }
public IDisposable ServiceRegistrationCallback(Type serviceType, string contract, Action <IDisposable> callback) { Tuple <Type, string> pair = Tuple.Create <Type, string>(serviceType, contract ?? string.Empty); if (!this._callbackRegistry.ContainsKey(pair)) { this._callbackRegistry[pair] = new List <Action <IDisposable> >(); } this._callbackRegistry[pair].Add(callback); ActionDisposable disposable = new ActionDisposable(delegate { this._callbackRegistry[pair].Remove(callback); }); if (this._registry.ContainsKey(pair)) { foreach (Func <object> local2 in this._registry[pair]) { callback(disposable); } } return(disposable); }