Exemplo n.º 1
0
        /// <summary>
        /// Gets locks on the required <c>object</c> from the specified <c>resolver</c>.
        /// </summary>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <returns>Temp <c>lock</c> on the <c>object</c>.</returns>
        public static async ValueTask <IxLock <T> > Get <T>(this IIxResolver resolver, string name = null)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            return(new IxLock <T>(await resolver.Resolve(new IxIdentifier(typeof(T), name))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves instance just to instantiate it.
        /// </summary>
        /// <remarks>
        /// In many cases this method should be replaced by https://github.com/dmitriyse/ClrCoder/issues/8 (Auto activateion).
        /// </remarks>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <returns>Async execution TPL task.</returns>
        public static async Task WarmUp <T>(this IIxResolver resolver, string name = null)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            using (await resolver.Resolve(new IxIdentifier(typeof(T), name)))
            {
                // Do nothing.
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets locks on the required <c>object</c> from the specified <c>resolver</c>.
        /// </summary>
        /// <typeparam name="T">Type of target <c>object</c>.</typeparam>
        /// <typeparam name="TArg1">The type of the argument for current resolve operation.</typeparam>
        /// <param name="resolver">Resolver that should be used.</param>
        /// <param name="name">Name of registration.</param>
        /// <param name="arg1">The argument for current resolve operation.</param>
        /// <returns>Temp <c>lock</c> on the <c>object</c>.</returns>
        public static async ValueTask <IxLock <T> > Get <T, TArg1>(
            this IIxResolver resolver,
            [CanBeNull] string name,
            TArg1 arg1)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            return(new IxLock <T>(
                       await resolver.Resolve(
                           new IxIdentifier(typeof(T), name),
                           new Dictionary <IxIdentifier, object>
            {
                { new IxIdentifier(typeof(TArg1)), arg1 }
            })));
        }