ServiceContainerException.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. namespace Wayne.Lib
  3. {
  4. /// <summary>
  5. /// Exception thrown by the service container.
  6. /// </summary>
  7. public class ServiceContainerException : ApplicationException
  8. {
  9. /// <summary>
  10. /// Type of service that this exception is about.
  11. /// </summary>
  12. public Type ServiceType { get; private set; }
  13. internal ServiceContainerException(Type serviceType, string message)
  14. : base(message)
  15. {
  16. ServiceType = serviceType;
  17. }
  18. /// <summary>
  19. /// Creates a new ServiceContainerException saying that a service was not found.
  20. /// </summary>
  21. /// <param name="type">Type of the service not found.</param>
  22. /// <returns>New ServiceContainerException.</returns>
  23. public static ServiceContainerException CreateNotFoundException(Type type)
  24. {
  25. return new ServiceContainerException(type, string.Format("Service {0} not found!", type));
  26. }
  27. /// <summary>
  28. /// Creates a new ServiceContainerException saying that a service's dependency was not found in the container.
  29. /// </summary>
  30. /// <param name="typeToCreate">Type of service that is being created.</param>
  31. /// <param name="dependency">Type of dependency not found.</param>
  32. /// <returns>New ServiceContainerException.</returns>
  33. public static ServiceContainerException CreateDependencyNotFound(Type typeToCreate, Type dependency)
  34. {
  35. return new ServiceContainerException(typeToCreate, string.Format("Type {0} could not be created because dependency {1} could not be found in the container!", typeToCreate, dependency));
  36. }
  37. }
  38. }