一个App架构例子分析--UI层使用MVP模式;各层之间使用Otto实现通信
2015-05-17 10:42 ttylinux 阅读(1033) 评论(0) 编辑 收藏 举报一、这个App整体的架构划分:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':domain')
compile project (':common')
compile project (':model')
compile project(':common')
compile 'com.squareup:otto:1.3.5'
compile 'com.google.dagger:dagger:2.0'
compile 'org.glassfish:javax.annotation:10.0-b28'
}
MoviesApp app = (MoviesApp) getApplication();
DaggerBasicMoviesUsecasesComponent.builder()
.appComponent(app.getAppComponent())
.basicMoviesUsecasesModule(new BasicMoviesUsecasesModule())
.build().inject(this);
}
package com.hackvg.android.di.components;
import com.hackvg.android.di.modules.BasicMoviesUsecasesModule;
import com.hackvg.android.di.scopes.PerActivity;
import com.hackvg.android.views.activities.MoviesActivity;
import dagger.Component;
@PerActivity
@Component(dependencies = AppComponent.class, modules = BasicMoviesUsecasesModule.class)
public interface BasicMoviesUsecasesComponent {
void inject (MoviesActivity moviesActivity);
}
}
package com.hackvg.android.di.modules;
import com.hackvg.domain.ConfigurationUsecase;
import com.hackvg.domain.ConfigurationUsecaseController;
import com.hackvg.domain.GetMoviesUsecase;
import com.hackvg.domain.GetMoviesUsecaseController;
import com.hackvg.model.rest.RestMovieSource;
import com.squareup.otto.Bus;
import dagger.Module;
import dagger.Provides;
@Module
public class BasicMoviesUsecasesModule {
@Provides ConfigurationUsecase provideConfigurationUsecase (Bus bus, RestMovieSource moviesSource) {
return new ConfigurationUsecaseController(moviesSource, bus);
}
@Provides GetMoviesUsecase provideMoviesUsecase (Bus bus, RestMovieSource movieSource) {
return new GetMoviesUsecaseController(movieSource, bus);
}
}
package com.hackvg.android.di.components;
import com.hackvg.android.di.modules.ApplicationModule;
import com.hackvg.android.di.modules.DomainModule;
import com.hackvg.model.rest.RestMovieSource;
import com.squareup.otto.Bus;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = {
ApplicationModule.class,
DomainModule.class,
})
public interface AppComponent {
Bus bus();
RestMovieSource restMovieSource();
}
package com.hackvg.android.di.modules;
import com.hackvg.model.rest.RestMovieSource;
import com.squareup.otto.Bus;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class DomainModule {
@Provides @Singleton Bus provideBus () {
return new Bus();
}
@Provides @Singleton RestMovieSource provideDataSource (Bus bus) { return new RestMovieSource(bus); }
}