コード例 #1
0
 /// <summary>
 /// The implementation method that constructs and/or returns the
 /// implementation instance.
 /// </summary>
 /// <param name="serviceConstructorRequest">This argument is required here.</param>
 /// <returns>Should be null only if the service is not constructed successfully:
 /// note that this may result in a resolver or constructor error.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 internal object Get(ServiceConstructorRequest serviceConstructorRequest)
 {
     if (serviceConstructorRequest == null)
     {
         throw new ArgumentNullException(nameof(serviceConstructorRequest));
     }
     lock (syncLock) {
         checkIsDisposedUnsafe();
         if (!IsSingleton)
         {
             ConstructedAt = DateTime.UtcNow;
             object instance = InvokeFactory(serviceConstructorRequest);
             if (dependencies != null)
             {
                 dependencies.TryAddRange(serviceConstructorRequest.Dependencies);
             }
             else
             {
                 dependencies
                     = new MultiDictionary <Type, Type>(
                           serviceConstructorRequest.Dependencies,
                           serviceConstructorRequest.Dependencies.Comparer);
             }
             return(instance);
         }
         if (IsSingletonSet)
         {
             return(singleton);
         }
         ConstructedAt  = DateTime.UtcNow;
         singleton      = InvokeFactory(serviceConstructorRequest);
         IsSingletonSet = true;
         dependencies
             = new MultiDictionary <Type, Type>(
                   serviceConstructorRequest.Dependencies,
                   serviceConstructorRequest.Dependencies.Comparer);
         return(singleton);
     }
     object InvokeFactory(ServiceConstructorRequest request)
     => factory != null
                                         ? factory(serviceProvider)
                                         : ServiceConstructorMethods.TryConstruct(
         ImplementationType,
         out object result,
         request,
         serviceProvider,
         null,
         false,
         RequireConstructorAttributes,
         ConstructorAttributeTypes)
                                                         ? result
                                                         : null;
 }