Skip to content

README: a Factories section - #49

Merged
floatdrop merged 1 commit into
mainfrom
readme-factories
Sep 11, 2026
Merged

README: a Factories section#49
floatdrop merged 1 commit into
mainfrom
readme-factories

Conversation

@floatdrop

Copy link
Copy Markdown
Owner

There is no transient lifetime, and the README never said what to do instead. This adds #### Factories to the Scopes part, between "Request scopes" and "Groups":

  • A value made fresh on every use is a function, registered like any service under a named function type, so two factories of one shape cannot collide and Explain and Wire have a name to show.
  • The container builds the factory once and never sees what it makes; the products are the caller's to release, as a *sql.Conn is, or the factory's to pool.
  • A value that needs a lifecycle of its own is Scoped(), resolved from a child scope per unit of work and stopped with it.
  • One line each on samber/do, whose ProvideTransient instances are not tracked either (checked in v2.1.0's source: shutdown and healthcheck are no-ops), and on fx, which has no transient and uses the same function.

examples/factory/main.go is the embedded program, 41 lines, shown open with its output. It is added to the CI list of short examples that are run as well as compiled.

Docs only: no CHANGELOG entry. embedmd is in sync, the examples module vets and tests, gofmt is clean.

🤖 Generated with Claude Code

There is no transient lifetime, and the README never said what to do
instead. The new section, in the Scopes part, says it: a value made fresh
on every use is a function, registered like any service under a named
function type; the container builds the factory once and never sees what
it makes, so the products are the caller's to release or the factory's to
pool; and a value that needs a lifecycle of its own is Scoped, resolved
from a child scope per unit of work and stopped with it. One line each on
samber/do's untracked ProvideTransient and on fx, which has no transient
and uses the same function.

examples/factory/main.go is the embedded program, run in CI beside the
other short examples.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@floatdrop
floatdrop merged commit c44198f into main Sep 11, 2026
4 checks passed
@floatdrop
floatdrop deleted the readme-factories branch September 11, 2026 05:54
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