001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2025 microBean™. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 006 * the License. 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 distributed under the License is distributed on 011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 012 * specific language governing permissions and limitations under the License. 013 */ 014package org.microbean.reference; 015 016import java.util.function.BooleanSupplier; 017import java.util.function.Supplier; 018 019import org.microbean.bean.Bean; 020import org.microbean.bean.Id; 021import org.microbean.bean.Creation; 022import org.microbean.bean.ReferencesSelector; 023 024/** 025 * A factory for {@link Supplier}s of contextual instances. 026 * 027 * <p>{@link Instances} instances are used by {@link Request} instances.</p> 028 * 029 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a> 030 * 031 * @see #supplier(Bean, Creation) 032 * 033 * @see Request 034 */ 035public interface Instances { 036 037 /** 038 * Returns {@code true} if and only if it is possible for a client proxy to be created for contextual instances 039 * described by the supplied {@link Id}. 040 * 041 * @param id an {@link Id}; must not be {@code null} 042 * 043 * @return {@code true} if and only if it is possible for a client proxy to be created for contextual instances 044 * described by the supplied {@link Id}; {@code false} otherwise 045 * 046 * @exception NullPointerException if {@code id} is {@code null} 047 */ 048 public boolean proxiable(final Id id); 049 050 /** 051 * Returns a {@link Supplier} of contextual instances appropriate for the given {@link Creation}. 052 * 053 * @param <I> the type of the contextual instance being requested 054 * 055 * @param bean the {@link Bean} whose {@link Bean#factory() Factory} will create any contextual instances; must not be 056 * {@code null} 057 * 058 * @param creation a {@link Creation}; may be {@code null} 059 * 060 * @return a non-{@code null} {@link Supplier} of contextual instances of the appropriate type 061 */ 062 public <I> Supplier<? extends I> supplier(final Bean<I> bean, final Creation<I> creation); 063 064}