001/*
002 * Copyright 2015-2018 Transmogrify LLC.
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 * http://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 com.pyranid;
018
019/**
020 * Contract for a factory that creates instances given a type.
021 * <p>
022 * Useful for resultset mapping, where each row in the resultset might require a new instance.
023 * <p>
024 * Implementors are suggested to employ application-specific strategies, such as having a DI container handle instance
025 * creation.
026 * 
027 * @author <a href="http://revetkn.com">Mark Allen</a>
028 * @since 1.0.0
029 */
030public interface InstanceProvider {
031  /**
032   * Provides an instance of the given {@code instanceClass}.
033   * <p>
034   * Whether the instance is new every time or shared/reused is implementation-dependent.
035   * 
036   * @param <T>
037   *          instance type token
038   * @param instanceClass
039   *          the type of instance to create
040   * @return an instance of the given {@code instanceClass}
041   */
042  <T> T provide(Class<T> instanceClass);
043}