Skip to content

Proposal (v2): Injector should implement context.Context #92

@diamondburned

Description

@diamondburned

Currently, do provides a Shutdown API for shutting down which can perform I/O or long-running operations, and ShutdownWithContext exists to allow the user to pass their context down to those operations. However, there isn't a Start equivalent for initializing services. As a result, the constructor is the only place to perform service initialization.

A problem arises when the constructor also tries to perform I/O or long-running operations, such as connecting to a database. There isn't a way to pass the user's context to those operations during construction. In my opinion, the easiest solution to this problem would be to:

  1. Make do.Injector also implement context.Context, and
  2. Add func do.InvokeContext[T](context.Context, do.Injector)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions