저는 일괄 처리와 같은 play-slick 및 프로그램과 함께 Playframework2.5에서 작업하고 있습니다. 내가 Guice DI 거의 모든 곳에서 데이터베이스 액세스 개체 (DAO)를 포함 사용하고 Scala에서 독립적으로 Playframework Guice를 통해 DI를 수행하는 클래스의 인스턴스를 만듭니다.
/rootPlayProject
/app
/controllers
/filters
/services
...
Modules
/core (sub-project - DAOs,services are placed here)
/batch (sub-project depends on core)
처럼
현재 프로젝트 구조는 다음과 같다. 코어의 인터페이스는 Module
에 배치되어 core
에 배치되며 루트 프로젝트에서는 Module
에 의해 상속됩니다.
코어 모듈 (/rootPlayProject/core/CoreModule.scala)
class CoreModule extends AbstractModule {
override def configure() = {
bind(classOf[FooDAO]).to(classOf[FooDAOImpl])
....
}
}
루트 모듈 (/rootPlayProject/Modules.scala)
이 비록 Playframework 응용 프로그램으로 꽤 잘 작동class Module extends CoreModule {
override def configure() = {
super.configure()
bind(classOf[FooService]).to(classOf[FooServiceImpl])
}
}
, I 배치 모듈 프로그램에 코어 모듈을 사용하고 싶습니다. 플레이 프레임 워크없이 배치를 실행하고 싶습니다.
지금까지 나는이
object BatchA {
def main(args: Array[String]) = {
val injector = Guice.createInjector(new CoreModule)
val foo = injector.getInstance(classOf[FooDAO])
//do something with foo.
}
}
처럼 뭔가를 시도했지만 내 DAO의 필요로하는 일을 만들 Playframework 이후 같은 ExecutionContext
, play.api.db.slick.DatabaseConfigProvider
및 @play.db.NamedDatabase
, 위의 코드를 실행하지 않습니다.
제 질문은, 어떻게하면 이러한 것들을 응용 프로그램 빌더 없이도 사용할 수 있습니까?
미리 감사드립니다.
'Option1'의 경우 내가 원하는 것을하는 동안 재생 응용 프로그램이 실행 중임을 의미합니까? 그렇게하기가 어렵지 않다면, 후자의 것을 선호하므로, exec 애플리케이션을 실행할 필요가 없습니다. – suish
귀하의 경우 옵션 2가 더 합리적 일 수 있습니다. – doctorless