Skip to content
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

experiment: diod di container #1

Merged
merged 6 commits into from
Nov 2, 2024
Merged

Conversation

mnahkies
Copy link
Owner

@mnahkies mnahkies commented Oct 13, 2024

playing around with using diod as a dependency injection container, using the changes from mnahkies/openapi-code-generator#256

notes:

  • import type doesn't work with diod - removes the information it uses for auto-wiring I guess
  • tsx also won't work with diod since it bypasses the typescript compiler

builder.registerAndUse(ReferenceManager)

builder.registerAndUse(GroupsRepository)
builder.register(IdpAdapter).use(FirebaseAuthService).asSingleton()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hacky, just to get the POC to work. It's to avoid re-initializing the firebase SDK, which throws an error. Should be refactored.

src/api.entrypoint.ts Outdated Show resolved Hide resolved
builder.registerAndUse(GroupsRepository)
builder.register(IdpAdapter).use(FirebaseAuthService).asSingleton()

builder.register(UsersImplementation).use(UsersHandlers)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I don't like about this is that it would seem to make it difficult inject things scoped/initialized with contextual configuration per request. Need experiment more with diod to figure out the best patterns

@mnahkies mnahkies marked this pull request as ready for review November 2, 2024 17:05
@mnahkies mnahkies merged commit 5e9e78b into main Nov 2, 2024
@mnahkies mnahkies deleted the mn/experiment/diod-di-container branch November 2, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant