Exemple #1
0
        /// <summary>
        /// Registers the disposable internal.
        /// </summary>
        /// <param name="contract">The contract.</param>
        /// <param name="implementation">The implementation.</param>
        private static void RegisterDisposableInternal(Type contract, Type implementation)
        {
            var lazyDisposable = new LazyDisposable <IDisposable>(() => (IDisposable)CreateInstance(implementation));

            Registrations.AddOrUpdate(contract,
                                      () =>
            {
                RegistrationsCalls[contract]++;
                lock (Locks.GetOrAdd(implementation.FullName ?? implementation.Name, new object()))
                {
                    return(lazyDisposable.Value);
                }
            },
                                      (key, existingValue) => () => existingValue);
        }
Exemple #2
0
        /// <summary>
        /// Registers the disposable internal.
        /// </summary>
        /// <typeparam name="TContract">The type of the t contract.</typeparam>
        /// <param name="instanceCreator">The instance creator.</param>
        /// <param name="contract">The contract.</param>
        private static void RegisterDisposableInternal <TContract>(Func <TContract> instanceCreator, Type contract)
        {
            var lazyDisposable = new LazyDisposable <IDisposable>(() => (IDisposable)instanceCreator());

            Registrations.AddOrUpdate(
                contract,
                () =>
            {
                RegistrationsCalls[contract]++;
                lock (Locks.GetOrAdd(contract.FullName ?? contract.Name, new object()))
                {
                    return(lazyDisposable.Value);
                }
            },
                (key, existingValue) => () => existingValue);
        }