Skip to content

Commit

Permalink
Revenj.scala v0.7.2
Browse files Browse the repository at this point in the history
Allow registration of unbounded instances into the container
  • Loading branch information
zapov committed May 18, 2018
1 parent c220209 commit e1f1c45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lazy val core = (project in file("revenj-core")
settings (commonSettings ++ publishSettings)
enablePlugins(SbtDslPlatformPlugin)
settings(
version := "0.7.1",
version := "0.7.2",
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "42.1.4",
"joda-time" % "joda-time" % "2.9.9", // TODO: will be removed
Expand All @@ -26,7 +26,7 @@ lazy val core = (project in file("revenj-core")
lazy val akka = (project in file("revenj-akka")
settings (commonSettings ++ publishSettings)
settings(
version := "0.7.1",
version := "0.7.2",
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.2",
"com.typesafe.akka" %% "akka-http-core" % "10.0.13"
Expand Down Expand Up @@ -56,7 +56,7 @@ lazy val tests = (project in file("tests")
name := "integration-tests",
version := "0.0.0",
libraryDependencies ++= Seq(
"com.dslplatform" % "dsl-clc" % "1.9.4" % Test,
"com.dslplatform" % "dsl-clc" % "1.9.6" % Test,
"org.specs2" %% "specs2-scalacheck" % "3.8.6" % Test,
"ru.yandex.qatools.embed" % "embedded-services" % "1.21" % Test
exclude ("org.xbib.elasticsearch.plugin", "elasticsearch-river-jdbc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ If you wish to resolve types not registered in the container, specify revenj.res
addToRegistry(new Registration[T](paramType, this, factory, lifetime))
}

override def registerInstance[T](manifest: JavaType, factory: () => T): this.type = {
val resolution: Container => T = _ => factory.apply()
addToRegistry(new Registration[T](manifest, this, resolution, InstanceScope.Singleton))
}

override def registerGenerics[T: TypeTag](factory: (Container, Array[JavaType]) => T, lifetime: InstanceScope = Transient): this.type = {
addToRegistry(new Registration[T](mirror.runtimeClass(mirror.typeOf[T]), this, factory, lifetime))
}
Expand Down Expand Up @@ -515,7 +520,7 @@ private object SimpleContainer {
val biFactory: Option[(Container, Array[JavaType]) => T],
val lifetime: InstanceScope) {

val name = signature.getTypeName
val name: String = signature.getTypeName

def this(signature: JavaType, owner: SimpleContainer, manifest: Class[T], lifetime: InstanceScope) {
this(None, signature, owner, Some(manifest), None, None, None, lifetime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trait Container extends ServiceLocator with AutoCloseable {
@deprecated("avoid using this unbounded method. Prefer bounded ones instead", "0.6.0")
def registerType[T](manifest: Type, implementation: Class[T], lifetime: InstanceScope = Transient): this.type

@deprecated("avoid using this unbounded method. Prefer bounded ones instead", "0.7.2")
def registerInstance[T](manifest: Type, factory: () => T): this.type

@deprecated("use register with InstanceScope instead", "0.5.3")
def register[T](singleton: Boolean)(implicit manifest: ClassTag[T]): this.type = {
registerType(manifest.runtimeClass, manifest.runtimeClass, if (singleton) Singleton else Transient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ class ContainerCheck extends Specification with ScalaCheck {
tryCol.isFailure === true
tryCol.failed.get.asInstanceOf[ReflectiveOperationException].getMessage == "Unable to resolve class net.revenj.ErrorInCollection. Error: naah"
}
"unbound func" >> {
val container = new SimpleContainer(false, cl)
val top = new CircularTop(new CircularDep(null))
container.registerInstance(classOf[CircularTop], () => top)
val resolved = container.resolve[CircularTop]
top === resolved
}
}
}

Expand Down

0 comments on commit e1f1c45

Please sign in to comment.