using System;
namespace Wayne.Lib
{
///
/// Exception thrown by the service container.
///
public class ServiceContainerException : ApplicationException
{
///
/// Type of service that this exception is about.
///
public Type ServiceType { get; private set; }
internal ServiceContainerException(Type serviceType, string message)
: base(message)
{
ServiceType = serviceType;
}
///
/// Creates a new ServiceContainerException saying that a service was not found.
///
/// Type of the service not found.
/// New ServiceContainerException.
public static ServiceContainerException CreateNotFoundException(Type type)
{
return new ServiceContainerException(type, string.Format("Service {0} not found!", type));
}
///
/// Creates a new ServiceContainerException saying that a service's dependency was not found in the container.
///
/// Type of service that is being created.
/// Type of dependency not found.
/// New ServiceContainerException.
public static ServiceContainerException CreateDependencyNotFound(Type typeToCreate, Type dependency)
{
return new ServiceContainerException(typeToCreate, string.Format("Type {0} could not be created because dependency {1} could not be found in the container!", typeToCreate, dependency));
}
}
}