001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.beans.factory;
018
019import org.springframework.beans.BeansException;
020
021/**
022 * A variant of {@link ObjectFactory} designed specifically for injection points,
023 * allowing for programmatic optionality and lenient not-unique handling.
024 *
025 * @author Juergen Hoeller
026 * @since 4.3
027 */
028public interface ObjectProvider<T> extends ObjectFactory<T> {
029
030        /**
031         * Return an instance (possibly shared or independent) of the object
032         * managed by this factory.
033         * <p>Allows for specifying explicit construction arguments, along the
034         * lines of {@link BeanFactory#getBean(String, Object...)}.
035         * @param args arguments to use when creating a corresponding instance
036         * @return an instance of the bean
037         * @throws BeansException in case of creation errors
038         * @see #getObject()
039         */
040        T getObject(Object... args) throws BeansException;
041
042        /**
043         * Return an instance (possibly shared or independent) of the object
044         * managed by this factory.
045         * @return an instance of the bean, or {@code null} if not available
046         * @throws BeansException in case of creation errors
047         * @see #getObject()
048         */
049        T getIfAvailable() throws BeansException;
050
051        /**
052         * Return an instance (possibly shared or independent) of the object
053         * managed by this factory.
054         * @return an instance of the bean, or {@code null} if not available or
055         * not unique (i.e. multiple candidates found with none marked as primary)
056         * @throws BeansException in case of creation errors
057         * @see #getObject()
058         */
059        T getIfUnique() throws BeansException;
060
061}