feat: BAC-39 Authentication (#114)
Reviewed-on: #114 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
22
knockoutwhistweb/app/di/EntityManagerProvider.scala
Normal file
22
knockoutwhistweb/app/di/EntityManagerProvider.scala
Normal file
@@ -0,0 +1,22 @@
|
||||
package di
|
||||
|
||||
import com.google.inject.Provider
|
||||
import com.google.inject.Inject
|
||||
import jakarta.inject.Singleton
|
||||
import jakarta.persistence.{EntityManager, EntityManagerFactory, Persistence}
|
||||
|
||||
@Singleton
|
||||
class EntityManagerProvider @Inject()() extends Provider[EntityManager] {
|
||||
|
||||
private val emf: EntityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit")
|
||||
|
||||
override def get(): EntityManager = {
|
||||
emf.createEntityManager()
|
||||
}
|
||||
|
||||
def close(): Unit = {
|
||||
if (emf.isOpen) {
|
||||
emf.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
25
knockoutwhistweb/app/di/ProductionModule.scala
Normal file
25
knockoutwhistweb/app/di/ProductionModule.scala
Normal file
@@ -0,0 +1,25 @@
|
||||
package di
|
||||
|
||||
import com.google.inject.AbstractModule
|
||||
import com.google.inject.name.Names
|
||||
import logic.user.impl.HibernateUserManager
|
||||
import play.api.db.DBApi
|
||||
import play.api.{Configuration, Environment}
|
||||
|
||||
class ProductionModule(
|
||||
environment: Environment,
|
||||
configuration: Configuration
|
||||
) extends AbstractModule {
|
||||
|
||||
override def configure(): Unit = {
|
||||
// Bind HibernateUserManager for production
|
||||
bind(classOf[logic.user.UserManager])
|
||||
.to(classOf[logic.user.impl.HibernateUserManager])
|
||||
.asEagerSingleton()
|
||||
|
||||
// Bind EntityManager for JPA
|
||||
bind(classOf[jakarta.persistence.EntityManager])
|
||||
.toProvider(classOf[EntityManagerProvider])
|
||||
.asEagerSingleton()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user