001package com.ericlam.mc.eld;
002
003import com.ericlam.mc.eld.components.Configuration;
004import com.ericlam.mc.eld.components.GroupConfiguration;
005import com.ericlam.mc.eld.components.GroupLangConfiguration;
006import com.ericlam.mc.eld.components.Overridable;
007
008import javax.inject.Provider;
009import java.util.Map;
010
011/**
012 * 服務註冊器
013 */
014public interface ServiceCollection {
015
016    /**
017     * 註冊單例
018     * @param singleton 單例
019     * @return this
020     */
021    ServiceCollection addSingleton(Class<?> singleton);
022
023    /**
024     * 註冊服務
025     * @param service 服務類 (interface)
026     * @param implementation 該服務的實作類
027     * @param <T> 服務
028     * @param <L> 實作
029     * @return this
030     */
031    <T, L extends T> ServiceCollection bindService(Class<T> service, Class<L> implementation);
032
033    /**
034     * 使用 Provider 註冊服務
035     * @param service 服務類 (interface)
036     * @param provider 該服務的提供器
037     * @param <T> 服務
038     * @param <P> 提供器
039     * @return this
040     */
041    <T, P extends Provider<T>> ServiceCollection bindServiceProvider(Class<T> service, Class<P> provider);
042
043
044    /**
045     * 獲取自定義安裝器,沒有時拋出異常
046     * @param cls 安裝器類
047     * @param <T> 安裝類
048     * @return this
049     */
050    <T> T getInstallation(Class<T> cls);
051
052
053    /**
054     * 覆蓋服務
055     * @param service 可覆蓋的服務類 (interface)
056     * @param implementation 新的實作
057     * @param <T> 可覆蓋的服務
058     * @param <L> 實作
059     * @return this
060     */
061    <T extends Overridable, L extends T> ServiceCollection overrideService(Class<T> service, Class<L> implementation);
062
063
064    /**
065     * 註冊服務, 如果已被註冊,則添加新的實作
066     * <br>
067     * 使用依賴注入時,請使用 {@code Set<[Service]> } 進行註冊
068     * @param service 服務類 (interface)
069     * @param implementation 新的實作
070     * @param <T> 服務
071     * @param <L> 實作
072     * @return this
073     */
074    <T, L extends T> ServiceCollection addService(Class<T> service, Class<L> implementation);
075
076
077    /**
078     * 註冊含有多重實作方式的服務, 如果先前已有註冊,將直接添加新的實作
079     * <br>
080     * 使用依賴注入時,請使用 {@code Map<String, [Service]> } 進行註冊
081     * @param service 服務類 (interface)
082     * @param implementations 包含標識id的多重實作類比
083     * @param <T> 服務
084     * @return this
085     */
086    <T> ServiceCollection addServices(Class<T> service, Map<String, Class<? extends T>> implementations);
087
088
089    /**
090     * 新增文件配置
091     * @param config 文件映射物件類
092     * @param <T> 映射物件類
093     * @return this
094     */
095    <T extends Configuration> ServiceCollection addConfiguration(Class<T> config);
096
097    /**
098     * 新增文件池
099     * @param config 文件
100     * @param <T> 映射物件類
101     * @return this
102     */
103    <T extends GroupConfiguration> ServiceCollection addGroupConfiguration(Class<T> config);
104
105
106    /**
107     * 新增訊息文件池
108     * @param lang 訊息文件
109     * @param <T> 映射物件類
110     * @return this
111     */
112    <T extends GroupLangConfiguration> ServiceCollection addMultipleLanguages(Class<T> lang);
113
114
115}