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.Supplier; 017 018import org.microbean.bean.Bean; 019import org.microbean.bean.Id; 020import org.microbean.bean.Creation; 021 022/** 023 * A factory for {@link Supplier}s of contextual instances. 024 * 025 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a> 026 * 027 * @see #supplier(Bean, Creation) 028 */ 029public interface Instances extends AutoCloseable { 030 031 @Override // AutoCloseable 032 public default void close() { 033 034 } 035 036 /** 037 * Returns {@code true} if and only if it is possible for a client proxy to be created for contextual instances 038 * described by the supplied {@link Id}. 039 * 040 * @param id an {@link Id}; must not be {@code null} 041 * 042 * @return {@code true} if and only if it is possible for a client proxy to be created for contextual instances 043 * described by the supplied {@link Id}; {@code false} otherwise 044 * 045 * @exception NullPointerException if {@code id} is {@code null} 046 */ 047 public boolean proxiable(final Id id); 048 049 /** 050 * Returns a {@link Supplier} of contextual instances appropriate for the given {@link Creation}. 051 * 052 * @param <I> the type of the contextual instance being requested 053 * 054 * @param bean the {@link Bean} whose {@link Bean#factory() Factory} will create any contextual instances; must not be 055 * {@code null} 056 * 057 * @param creation a {@link Creation}; may be {@code null} 058 * 059 * @return a non-{@code null} {@link Supplier} of contextual instances of the appropriate type 060 */ 061 public <I> Supplier<? extends I> supplier(final Bean<I> bean, final Creation<I> creation); 062 063}