diff --git a/scala/build.sbt b/scala/build.sbt index 6f6612d1..6e5eaae8 100644 --- a/scala/build.sbt +++ b/scala/build.sbt @@ -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 @@ -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" @@ -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") diff --git a/scala/revenj-core/src/main/scala/net/revenj/SimpleContainer.scala b/scala/revenj-core/src/main/scala/net/revenj/SimpleContainer.scala index b3ceff47..eaf7a639 100644 --- a/scala/revenj-core/src/main/scala/net/revenj/SimpleContainer.scala +++ b/scala/revenj-core/src/main/scala/net/revenj/SimpleContainer.scala @@ -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)) } @@ -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) diff --git a/scala/revenj-core/src/main/scala/net/revenj/extensibility/Container.scala b/scala/revenj-core/src/main/scala/net/revenj/extensibility/Container.scala index 0246f5c1..48b2a5b1 100644 --- a/scala/revenj-core/src/main/scala/net/revenj/extensibility/Container.scala +++ b/scala/revenj-core/src/main/scala/net/revenj/extensibility/Container.scala @@ -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) diff --git a/scala/revenj-core/src/test/scala/net/revenj/ContainerCheck.scala b/scala/revenj-core/src/test/scala/net/revenj/ContainerCheck.scala index aad6e6f5..d6e60a06 100644 --- a/scala/revenj-core/src/test/scala/net/revenj/ContainerCheck.scala +++ b/scala/revenj-core/src/test/scala/net/revenj/ContainerCheck.scala @@ -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 + } } }