@@ -0,0 +1,2583 @@
+package me.jessyan.art.mvp;%0A%0Aimport java.lang.reflect.Constructor;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.Map;%0A%0Aimport javax.inject.Inject;%0Aimport javax.inject.Singleton;%0A%0Aimport me.jessyan.art.http.BaseCacheManager;%0Aimport me.jessyan.art.http.BaseServiceManager;%0A%0A/**%0A * Created by jess on 16/03/2017 14:25%0A * Contact with jess.yan.effort@gmail.com%0A */%0A%0A@Singleton%0Apublic class RepositoryManager%3CS extends BaseServiceManager, C extends BaseCacheManager%3E %7B%0A    protected S mServiceManager;//%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E7%B1%BB,%E7%94%A8%E4%BA%8E%E7%BD%91%E7%BB%9C%E8%AF%B7%E6%B1%82%0A    protected C mCacheManager;//%E7%BC%93%E5%AD%98%E7%AE%A1%E7%90%86%E7%B1%BB,%E7%94%A8%E4%BA%8E%E7%AE%A1%E7%90%86%E6%9C%AC%E5%9C%B0%E6%88%96%E8%80%85%E5%86%85%E5%AD%98%E7%BC%93%E5%AD%98%0A    private final Map%3CString, IModel%3E mRepositoryCache = new LinkedHashMap%3C%3E();%0A%0A    @Inject%0A    public RepositoryManager(S serviceManager, C cacheManager) %7B%0A        this.mServiceManager = serviceManager;%0A        this.mCacheManager = cacheManager;%0A    %7D%0A%0A    public %3CT extends IModel%3E T createRepository(Class%3CT%3E repository) %7B%0A        T repositoryInstance;%0A        synchronized (mRepositoryCache) %7B%0A            repositoryInstance = (T) mRepositoryCache.get(repository.getName());%0A            if (repositoryInstance == null) %7B%0A                Constructor%3C? extends IModel%3E constructor = findConstructorForClass(repository);%0A                try %7B%0A                    repositoryInstance = (T) constructor.newInstance(this);%0A                %7D catch (InstantiationException e) %7B%0A                    throw new RuntimeException(%22Unable to invoke %22 + constructor, e);%0A                %7D catch (IllegalAccessException e) %7B%0A                    throw new RuntimeException(%22Unable to invoke %22 + constructor, e);%0A                %7D catch (InvocationTargetException e) %7B%0A                    throw new RuntimeException(%22create repository error%22,e);%0A                %7D%0A                mRepositoryCache.put(repository.getName(), repositoryInstance);%0A            %7D%0A        %7D%0A        return repositoryInstance;%0A    %7D%0A%0A%0A    public S getServiceManager() %7B%0A        return mServiceManager;%0A    %7D%0A%0A    public C getCacheManager() %7B%0A        return mCacheManager;%0A    %7D%0A%0A    private static Constructor%3C? extends IModel%3E findConstructorForClass(Class%3C?%3E cls) %7B%0A        Constructor%3C? extends IModel%3E bindingCtor = null;%0A%0A        String clsName = cls.getName();%0A%0A        try %7B%0A            //noinspection unchecked%0A            bindingCtor = (Constructor%3C? extends IModel%3E) cls.getConstructor(RepositoryManager.class);%0A%0A        %7D catch (NoSuchMethodException e) %7B%0A            throw new RuntimeException(%22Unable to find constructor for %22 + clsName, e);%0A        %7D%0A%0A        return bindingCtor;%0A    %7D%0A%0A%0A%7D%0A

add RepositoryManager