/// <summary>
        /// Registers a service of the type specified in <paramref name="serviceType"/> with an
        /// implementation type specified in <paramref name="implementationType"/> as a lazy singleton.
        /// </summary>
        /// <param name="resolver">The <see cref="IMutableDependencyResolver"/> to register the service to.</param>
        /// <param name="implementationType">The type of the implementation to use.</param>
        /// <param name="serviceType">The type of the service to register.</param>
        /// <param name="contract">Can be used to isolate multiple <paramref name="implementationType"/> for
        /// the same <paramref name="serviceType"/>.
        /// </param>
        public static void RegisterLazySingleton(this IMutableDependencyResolver resolver, Type implementationType, Type serviceType, string contract = null)
        {
            ClassInstanceFactory classInstanceFactory = null;

            resolver.RegisterLazySingleton(() =>
            {
                if (classInstanceFactory == null)
                {
                    classInstanceFactory = GetClassInstanceFactory(resolver, implementationType, contract);
                }

                return(classInstanceFactory.Create());
            }, serviceType, contract);
        }
        private static ClassInstanceFactory GetClassInstanceFactory(IMutableDependencyResolver resolver, Type implementer, string contract = null)
        {
            var result = new ClassInstanceFactory();

            result.Constructor = implementer.GetTypeInfo().DeclaredConstructors.FirstOrDefault(c => c.IsPublic);
            var constructorParameters = result.Constructor.GetParameters();

            result.Parameters = new object[constructorParameters.Length];
            for (var i = 0; i < constructorParameters.Length; i++)
            {
                result.Parameters[i] = resolver.GetService(constructorParameters[i].ParameterType, contract);
                if (result.Parameters[i] == null)
                {
                    throw new ResolveException($"Unable to resolve {constructorParameters[i].Name} parameter for {implementer.Name}");
                }
            }

            return(result);
        }