001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2023–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.bean; 015 016/** 017 * An interface whose implementations {@linkplain #initialize(Object, Request) initialize} contextual instances. 018 * 019 * <p>{@link Initializer}s are subordinate to {@link Producer}s, typically operating on the contextual instances they 020 * produce.</p> 021 * 022 * @param <I> the type of contextual instance 023 * 024 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a> 025 * 026 * @see #initialize(Object, Request) 027 */ 028// Subordinate to Factory<I> (really to PostInitializer<I>). Normally applied to Producer<I> output. 029// Calls initializer methods and injects fields 030// Note that this deliberately extends Aggregate, providing access to dependencies. 031public interface Initializer<I> extends Aggregate { 032 033 /** 034 * Initializes the supplied contextual instance, possibly using the supplied {@link Request} to obtain supporting 035 * contextual references. 036 * 037 * <p>Typically {@link Initializer} implementations will call <dfn>initializer methods</dfn> and perform <dfn>field 038 * injection</dfn> on the supplied contextual instance.</p> 039 * 040 * @param i the contextual instance to initialize; may be {@code null} 041 * 042 * @param r a {@link Request} that can be used to acquire supporting contextual references; may be {@code null} 043 * 044 * @return the initialized instance, or a copy of it, or a stand-in for it 045 * 046 * @see Producer#produce(Request) 047 */ 048 public I initialize(final I i, final Request<I> r); 049 050}