/// <summary>
        /// Gets a service instance from a specified interface contract.
        /// </summary>
        /// <typeparam name="T">Type of the interface contract of the service</typeparam>
        /// <param name="registry">The registry.</param>
        /// <param name="serviceReady">The service ready.</param>
        /// <returns>An instance of the requested service registered to this registry.</returns>
        /// <exception cref="ServiceNotFoundException">If the service was not found</exception>
        public static void GetServiceLate <T>([NotNull] this IServiceRegistry registry, Action <T> serviceReady)
        {
            var instance = GetServiceAs <T>(registry);

            if (Equals(instance, null))
            {
                var deferred = new ServiceDeferredRegister <T>(registry, serviceReady);
                deferred.Register();
            }
            else
            {
                serviceReady(instance);
            }
        }
Example #2
0
        /// <summary>
        /// Gets a service instance from a specified interface contract.
        /// </summary>
        /// <typeparam name="T">Type of the interface contract of the service</typeparam>
        /// <param name="registry">The registry.</param>
        /// <param name="serviceReady">The service ready.</param>
        /// <returns>An instance of the requested service registered to this registry.</returns>
        /// <exception cref="ServiceNotFoundException">If the service was not found</exception>
        public static void GetServiceLate <T>([NotNull] this IServiceRegistry registry, [NotNull] Action <T> serviceReady)
            where T : class
        {
            var service = registry.GetService <T>();

            if (service == null)
            {
                var deferred = new ServiceDeferredRegister <T>(registry, serviceReady);
                deferred.Register();
            }
            else
            {
                serviceReady(service);
            }
        }