Beispiel #1
0
        /// <summary>
        /// Resolves the given resolution request, using the given service registration.
        /// </summary>
        /// <param name="request">Request.</param>
        /// <param name="registration">Registration.</param>
        protected virtual ResolutionResult Resolve(ResolutionRequest request, IServiceRegistration registration)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            AssertIsValidRequest(request);

            if (registration == null)
            {
                return(ResolutionResult.Failure(request.ResolutionPath));
            }

            var factory = registration.GetFactoryAdapter(request);

            if (factory == null)
            {
                return(ResolutionResult.Failure(request.ResolutionPath));
            }

            var resolved = instanceCreator.CreateFromFactory(factory, request.ResolutionPath, registration);

            InvokeServiceResolved(registration, resolved);
            return(ResolutionResult.Success(request.ResolutionPath, resolved));
        }
Beispiel #2
0
        /// <summary>
        /// Asserts that a resolution request is valid.
        /// </summary>
        /// <param name="request">Request.</param>
        protected virtual void AssertIsValidRequest(ResolutionRequest request)
        {
            var serviceType = request.ServiceType;

            if (serviceType.GetTypeInfo().IsPrimitive || serviceType.GetTypeInfo().IsValueType || serviceType == typeof(string))
            {
                var message = String.Format(Resources.ExceptionFormats.PrimitiveTypesCannotBeResolved, request);
                throw new InvalidResolutionRequestException(message)
                      {
                          ResolutionPath = request.ResolutionPath
                      };
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets a registration which matches the given resolution request.
        /// </summary>
        /// <returns>The registration.</returns>
        /// <param name="request">Request.</param>
        public override IServiceRegistration GetRegistration(ResolutionRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (registrationProvider.CanFulfilRequest(request))
            {
                return(registrationProvider.Get(request));
            }

            var requestWithoutName = request.GetCopyWithoutName();

            if (registrationProvider.CanFulfilRequest(requestWithoutName))
            {
                return(registrationProvider.Get(requestWithoutName));
            }

            return(null);
        }
Beispiel #4
0
 /// <summary>
 /// Gets the registration which corresponds to a given resolution request.
 /// </summary>
 /// <returns>The registration.</returns>
 /// <param name="request">Request.</param>
 public override IServiceRegistration GetRegistration(ResolutionRequest request)
 => ProxiedResolver.GetRegistration(request);
Beispiel #5
0
 /// <summary>
 /// Gets a value indicating whether or not this resolution path instance contains a registration for the given
 /// resolution request.
 /// </summary>
 /// <returns>
 /// <c>true</c> if this path contains a registration for the specified request; <c>false</c> otherwise.
 /// </returns>
 /// <param name="request">Request.</param>
 public bool Contains(ResolutionRequest request) => Contains(request.ServiceType, request.Name);
Beispiel #6
0
        /// <summary>
        /// Resolves the given resolution request and returns the result.
        /// </summary>
        /// <param name="request">Request.</param>
        public override ResolutionResult Resolve(ResolutionRequest request)
        {
            var registration = GetRegistration(request);

            return(Resolve(request, registration));
        }
Beispiel #7
0
 ResolutionResult IResolvesRegistrations.Resolve(ResolutionRequest request, IServiceRegistration registration)
 => Resolve(request, registration);
Beispiel #8
0
 /// <summary>
 /// Resolves the given resolution request and returns the result.
 /// </summary>
 /// <param name="request">Request.</param>
 public abstract ResolutionResult Resolve(ResolutionRequest request);
Beispiel #9
0
 /// <summary>
 /// Gets a registration which matches the given resolution request.
 /// </summary>
 /// <returns>The registration.</returns>
 /// <param name="request">Request.</param>
 public abstract IServiceRegistration GetRegistration(ResolutionRequest request);