##// END OF EJS Templates
ServiceLocator: fixed services cleanup
cin -
r88:c4877ae77cee v2
parent child
Show More
@@ -20,13 +20,11 namespace Implab {
20 public void Dispose() {
20 public void Dispose() {
21 if (shared)
21 if (shared)
22 return;
22 return;
23 if (cleanup != null)
23 if (cleanup != null) {
24 cleanup(service);
24 if (service != null)
25 else {
25 cleanup(service);
26 var d = service as IDisposable;
26 } else
27 if (d != null)
27 Safe.Dispose(service);
28 d.Dispose();
29 }
30 }
28 }
31
29
32 #endregion
30 #endregion
@@ -173,10 +171,11 namespace Implab {
173
171
174 Unregister(typeof(T));
172 Unregister(typeof(T));
175
173
176 m_services[typeof(T)] = new ServiceEntry {
174 var serviceEntry = new ServiceEntry();
177 activator = () => activator(),
175 serviceEntry.activator = () => activator();
178 cleanup = instance => cleanup((T)instance)
176 if (cleanup != null)
179 };
177 serviceEntry.cleanup = instance => cleanup((T)instance);
178 m_services[typeof(T)] = serviceEntry;
180 }
179 }
181
180
182 public void Register<T>(Func<T> activator) {
181 public void Register<T>(Func<T> activator) {
General Comments 0
You need to be logged in to leave comments. Login now