    public static class ServiceLocatorExtensions
    {

        public static object Resolve(this IServiceLocator locator, Type type, string key = null)
        {
            try
            {
                return string.IsNullOrEmpty(key) ? locator.GetInstance(type) : locator.GetInstance(type, key);
            }
            catch (ActivationException)
            {
                return null;
            }