/// <summary> /// Instantiates the service described by the <paramref name="serviceRequest"/>. /// </summary> /// <param name="serviceRequest">The <see cref="IServiceRequest"/> that describes the service that needs to be instantiated.</param> /// <returns>A valid object reference if the service can be found; otherwise, it will return <c>null</c>.</returns> public virtual object GetService(IServiceRequest serviceRequest) { // Allow users to intercept the instantiation process if (_preProcessor != null) _preProcessor.Preprocess(serviceRequest); var factoryRequest = new FactoryRequest { ServiceType = serviceRequest.ServiceType, ServiceName = serviceRequest.ServiceName, Arguments = serviceRequest.ActualArguments, Container = _container }; var instance = _creator.CreateFrom(factoryRequest, serviceRequest.ActualFactory); // Postprocess the results var result = new ServiceRequestResult { ServiceName = serviceRequest.ServiceName, ActualResult = instance, Container = _container, OriginalResult = instance, ServiceType = serviceRequest.ServiceType, AdditionalArguments = serviceRequest.ActualArguments }; if (_postProcessor != null) _postProcessor.PostProcess(result); return result.ActualResult ?? result.OriginalResult; }
/// <summary> /// Instantiates the service described by the <paramref name="serviceRequest"/>. /// </summary> /// <param name="serviceRequest">The <see cref="IServiceRequest"/> that describes the service that needs to be instantiated.</param> /// <returns>A valid object reference if the service can be found; otherwise, it will return <c>null</c>.</returns> public virtual object GetService(IServiceRequest serviceRequest) { // Allow users to intercept the instantiation process if (_preProcessor != null) { _preProcessor.Preprocess(serviceRequest); } var factoryRequest = new FactoryRequest { ServiceType = serviceRequest.ServiceType, ServiceName = serviceRequest.ServiceName, Arguments = serviceRequest.ActualArguments, Container = _container }; var instance = _creator.CreateFrom(factoryRequest, serviceRequest.ActualFactory); // Postprocess the results var result = new ServiceRequestResult { ServiceName = serviceRequest.ServiceName, ActualResult = instance, Container = _container, OriginalResult = instance, ServiceType = serviceRequest.ServiceType, AdditionalArguments = serviceRequest.ActualArguments }; if (_postProcessor != null) { _postProcessor.PostProcess(result); } return(result.ActualResult ?? result.OriginalResult); }