-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any complete example of Distage usage that doesn't involve ZIO? #2043
Comments
@OOPMan Not first-party, but there's an example project using cats-effect (and tofu) + distage - https://github.com/terjokhin/helpful - it might be outdated though. It might be a bit too large a project to use as an example, but the https://github.com/BlueBrain/nexus/ uses distage with cats-effect. For actually running on cats IO instead of ZIO, there aren't many changes you have to make compared to distage-example project:
As for EDIT: If you're not using either ZIO or Cats Effect, then the prescription is simpler:
You can find |
@neko-kai I think maybe you misunderstood. I'm trying to use distage without using ZIO, Cats or anything like that. As mentioned, I can get stuff with
Do I HAVE to use something like ZIO or Cats to make this work? From what I saw in the documentation it seemed like this wasn't necessarily the case? |
Sorry, meant to include some sample code as well import distage._
trait A:
def run(s: String) = s + " " + s
class anA extends A
trait B:
val a: A
def run(s: String) = s + a.run(s)
class aB(override val a: A) extends B
val testModule = new ModuleDef:
make[A].from[anA]
make[B].from[aB]
object Test:
val injector = Injector()
def main(args: Array[String]): Unit =
// This works
val (a, b) = injector.produceGet[B](testModule).unsafeAllocate()
println(a.run("test"))
b.apply()
// This doesn't, failing when I attempt to make use of the .use pathway due to missing implicit
val p = injector.plan(testModule, Activation.empty, Roots.target[B]).getOrThrow()
val r = injector.produce(p)
r.use {
os => os.get[B].run("zing")
} |
@OOPMan import distage._
trait A:
def run(s: String) = s + " " + s
class anA extends A
trait B:
val a: A
def run(s: String) = s + a.run(s)
class aB(override val a: A) extends B
val testModule = new ModuleDef:
make[A].from[anA]
make[B].from[aB]
object Test:
val injector = Injector()
def main(args: Array[String]): Unit =
injector.produceRun(testModule) {
(b: B) => println(b.run("zing"))
} I'll see if I can fix it. In the meantime you should be able to avoid it by passing |
@neko-kai Oh man, to think it was so simple XD Thanks a lot :-) |
@neko-kai Oh sweet, I found a weird Scala bug :-) |
Hi there, I'm curious as to whether there is any example code that demonstrates using Distage without ZIO?
All the code in the example application and on the site involve ZIO but according to the page the framework is actually agnostic about this kind of thing?
I played with some code on my side and got a basic plugin injection system working with minimal issues but with the caveat that whenever I want to use the injector I have to do an
unsafeGet
. Obviously littering my code with stuff labelled unsafe makes me feel...well...unsafe, so I was wondering if there is another accepted way to do things "safely" in a basic Scala application that is not using ZIO, Cats or any other similar frameworks.The text was updated successfully, but these errors were encountered: