Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
injector: Move builder to separate class and utils to separate classes
- Loading branch information
Showing
9 changed files
with
993 additions
and
810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
common-parent/injector/src/main/java/com/speedment/common/injector/InjectorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* | ||
* Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); You may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.speedment.common.injector; | ||
|
||
import com.speedment.common.injector.exception.NoDefaultConstructorException; | ||
import java.nio.file.Path; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Builder pattern for the {@link Injector} interface. | ||
* | ||
* @author Emil Forslund | ||
* @since 1.2.0 | ||
*/ | ||
public interface InjectorBuilder { | ||
|
||
/** | ||
* Appends a class that can be automatically dependency injected into | ||
* other classes to the builder. Classes can be appended in any order. | ||
* The final injection order will be determined once the | ||
* {@link #build()}-method is called. | ||
* <p> | ||
* If a class has already been passed as injectable with the same | ||
* InjectorKey, the previous one will be replaced by this new one. The | ||
* old one will never be instantiated. | ||
* <p> | ||
* This method will not replace any previous injectables. | ||
* | ||
* @param injectableType the type that should be injectable | ||
* @return a reference to this builder | ||
* | ||
* @throws NoDefaultConstructorException if the specified type does not | ||
* have a default constructor. | ||
*/ | ||
InjectorBuilder withComponent(Class<?> injectableType) | ||
throws NoDefaultConstructorException; | ||
|
||
/** | ||
* Puts one or multiple classes contained in an InjectBundle that can be | ||
* automatically dependency injected into other classes to the builder. | ||
* Classes can be appended in any order. The final injection order will | ||
* be determined once the {@link #build()}-method is called. | ||
* <p> | ||
* If an injectable class has already been passed as injectable with the | ||
* same key, the previous one will be replaced by this new one. The old | ||
* one will never be instantiated. | ||
* | ||
* @param bundleClass containing the injectable classes that shall be | ||
* appended | ||
* @return a reference to this builder | ||
* | ||
* @throws NoDefaultConstructorException if the specified type does not | ||
* have a default constructor. | ||
*/ | ||
InjectorBuilder withBundle(Class<? extends InjectBundle> bundleClass) | ||
throws NoDefaultConstructorException; | ||
|
||
/** | ||
* Overrides a particular configuration parameter in the config file | ||
* with the specified value. | ||
* | ||
* @param name the key to override | ||
* @param value the new value | ||
* @return a reference to this builder | ||
*/ | ||
InjectorBuilder withParam(String name, String value); | ||
|
||
/** | ||
* Sets the location of the configuration file. | ||
* | ||
* @param configFile the new config file location | ||
* @return a reference to this builder | ||
*/ | ||
InjectorBuilder withConfigFileLocation(Path configFile); | ||
|
||
/** | ||
* Appends an action that must be executed sometime before specified | ||
* type reaches the {@link State#INITIALIZED} state. The action will | ||
* have access to the instance as it is configured. This is equivalent | ||
* to using the {@link ExecuteBefore}-annotation on a method in the | ||
* class. | ||
* | ||
* @param <T> the injectable type | ||
* @param injectableType the injectable type | ||
* @param action action to be applied before state is reached | ||
* @return a reference to this builder | ||
*/ | ||
<T> InjectorBuilder beforeInitialized(Class<T> injectableType, Consumer<T> action); | ||
|
||
/** | ||
* Appends an action that must be executed sometime before specified | ||
* type reaches the {@link State#RESOLVED} state. The action will | ||
* have access to the instance as it is configured. This is equivalent | ||
* to using the {@link ExecuteBefore}-annotation on a method in the | ||
* class. | ||
* | ||
* @param <T> the injectable type | ||
* @param injectableType the injectable type | ||
* @param action action to be applied before state is reached | ||
* @return a reference to this builder | ||
*/ | ||
<T> InjectorBuilder beforeResolved(Class<T> injectableType, Consumer<T> action); | ||
|
||
/** | ||
* Appends an action that must be executed sometime before specified | ||
* type reaches the {@link State#STARTED} state. The action will | ||
* have access to the instance as it is configured. This is equivalent | ||
* to using the {@link ExecuteBefore}-annotation on a method in the | ||
* class. | ||
* | ||
* @param <T> the injectable type | ||
* @param injectableType the injectable type | ||
* @param action action to be applied before state is reached | ||
* @return a reference to this builder | ||
*/ | ||
<T> InjectorBuilder beforeStarted(Class<T> injectableType, Consumer<T> action); | ||
|
||
/** | ||
* Appends an action that must be executed sometime before specified | ||
* type reaches the {@link State#STOPPED} state. The action will | ||
* have access to the instance as it is configured. This is equivalent | ||
* to using the {@link ExecuteBefore}-annotation on a method in the | ||
* class. | ||
* | ||
* @param <T> the injectable type | ||
* @param injectableType the injectable type | ||
* @param action action to be applied before state is reached | ||
* @return a reference to this builder | ||
*/ | ||
<T> InjectorBuilder beforeStopped(Class<T> injectableType, Consumer<T> action); | ||
|
||
/** | ||
* Builds the {@link Injector} instance, organizing the | ||
* injectable instances based on their internal dependencies. | ||
* | ||
* @return the built instance | ||
* | ||
* @throws InstantiationException if one of the injectables can not | ||
* be instantiated. | ||
*/ | ||
Injector build() throws InstantiationException; | ||
|
||
} |
Oops, something went wrong.