Permalink
Browse files

Add some utility methods to ServiceManager

  • Loading branch information...
1 parent 695e976 commit dfd55b4b68521fa6759c9bacaac7ceb1faf0a6cd @cdhowie committed Jan 3, 2013
Showing with 18 additions and 0 deletions.
  1. +18 −0 Cdh.Toolkit.Services/ServiceManager.cs
@@ -53,6 +53,12 @@ public void RegisterService(IService service)
services.Add(service);
}
+ public void RegisterAndStartService(IService service)
+ {
+ RegisterService(service);
+ service.Start();
+ }
+
public void UnregisterService(IService service)
{
if (service == null)
@@ -65,5 +71,17 @@ public void UnregisterService(IService service)
{
return services.OfType<T>().SingleOrDefault();
}
+
+ public T RequireService<T>() where T : IService
+ {
+ var service = GetService<T>();
+
+ if (service == null) {
+ throw new InvalidOperationException(string.Format(
+ "Requested service type {0} not registered.", typeof(T).FullName));
+ }
+
+ return service;
+ }
}
}

0 comments on commit dfd55b4

Please sign in to comment.