#Dependency injection deno deploy

1 messages · Page 1 of 1 (latest)

molten pulsar
#

Does anyone know a Decency Injection library or container that works on deno deploy?

lament stormBOT
lilac spoke
#

what have you tried?

#

i like the inversify lib and have used it on some deno projects (not deno deploy) and it just works

molten pulsar
#

It fails to deploy, using tsyringe

import "npm:reflect-metadata";
import { injectable, container } from "npm:tsyringe";

class Some {
  constructor() { }

  some() {
    return "some"
  }
}

@injectable()
class Foo {
  constructor(private some: Some) { }
  callSome() {
    return this.some.some();
  }
}

const foo = container.resolve(Foo);

Deno.serve(() => {
  return new Response(foo.callSome())
})

Error

Task deploy deployctl deploy --project=hard-clam-29 main.ts
ℹ Using config file '/Users/franciscoramos/Documents/clau/code/clau/test/deno.json'
⚠ No entrypoint provided with either the --entrypoint arg or a config file. I've guessed 'main.ts' for you.
  ℹ Is this wrong? Please let us know in https://github.com/denoland/deployctl/issues/new
✔ Deploying to project hard-clam-29.
✔ Entrypoint: /Users/franciscoramos/Documents/clau/code/clau/test/main.ts
ℹ Uploading all files from the current dir (/Users/franciscoramos/Documents/clau/code/clau/test)
✔ Found 3 assets.
✔ Uploaded 1 new asset.
✖ Deployment failed.
error: The deployment failed: UNCAUGHT_EXCEPTION

Error: TypeInfo not known for "Foo"
    at file:///node_modules/.deno/[email protected]/node_modules/tsyringe/dist/cjs/dependency-container.js:292:27
    at InternalDependencyContainer.construct (file:///node_modules/.deno/[email protected]/node_modules/tsyringe/dist/cjs/dependency-container.js:297:11)
    at InternalDependencyContainer.resolve (file:///node_modules/.deno/[email protected]/node_modules/tsyringe/dist/cjs/dependency-container.js:114:33)
    at file:///src/main.ts:20:23
error: Uncaught (in promise) Error: Exited with code: 1
            throw new Error(`Exited with code: ${code}`);
                  ^
    at CommandChild.pipedStdoutBuffer (https://deno.land/x/[email protected]/src/command.ts:710:19)
    at eventLoopTick (ext:core/01_core.js:63:7)

lilac spoke
#

have you configured experimentalDecorators and emitDecoratorMetadata?

molten pulsar
#

Yes, inside deno.json

#

It works locally

fringe raven
#

if it doesn't work locally in an older version of Deno (like 1.39), then the error in Deploy is probably because they haven't updated Deno to the latest version on Deploy yet. In that case you just have to wait