Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Releases: floatdrop/di

v0.16.2

Choose a tag to compare

@github-actions github-actions released this 13 Sep 17:54
a91c68e

A faster warm path and four lifecycle fixes. go doc -all against 0.16.1 is
unchanged in di, dihttp and dislog apart from the package doc's own
text; an upgrade cannot break a caller.

Changed

  • A warm resolution, of a service that is already built, no longer takes a
    mutex in the scope that owns it, and observers are called without one.
    Every Get of an application singleton used to serialise on the
    application scope, so it got slower per call as cores were added: 46 ns on
    one core and 418 ns on eight, on an M3 Max. It is now 44 ns and 55 ns, and
    a whole request scope at eight cores went from 2.3 µs to 1.4 µs.
    No API or behaviour changes; the new benchmarks/parallel_test.go records
    the shapes.
  • The cycle check a resolution makes before waiting on another goroutine's
    build no longer scans every waiting resolution in the container. Many
    resolutions arriving at one slow constructor made it quadratic under the
    container's one lock: 8192 of them took over 300 ms to settle and now take
    about 20 ms on an M3 Max (BenchmarkDI_Herd_8192 in
    benchmarks/parallel_test.go).

Fixed

  • A Wrap in a child scope no longer keeps the parent's registration from
    being overridden after the child has stopped. The parent's Override() was
    rejected as "wrapped at" a site in a scope that no longer existed. The same
    held after the child overrode its own wrapper. A wrapper in a live scope
    still guards what it wraps, including when a sibling scope that wrapped the
    same registration has stopped.
  • A service that was built and waiting for its start step when a drain swept
    past it now gets its OnDrain once it starts. The sweep decided it owed
    nothing, since it had not started, and made that final, so a Stop issued
    while Start was still starting earlier services released it with OnStop
    and no OnDrain. The drain phase also no longer misses a service built
    between its last sweep and the scope being marked stopped: the phase ends
    only when nothing in the scope's subtree has been built or started since
    that sweep began. So a Stop goes round again while anything below
    it is still being built or started, and under work that never quiets it
    returns when its context expires.

v0.16.1

Choose a tag to compare

@github-actions github-actions released this 12 Sep 12:40
14d3708

One fix. go doc -all against 0.16.0 is unchanged in di, dihttp and
dislog; an upgrade cannot break a caller.

Fixed

  • A worker registered with Go that panics is now a worker that failed: the
    panic becomes its error, Shutdown receives it, Run returns it, OnStop
    runs and the stop event carries it, as for a panicking hook. It was the one
    user function not called through the recovering wrapper, so its panic took
    the process down with no release and no event.

v0.16.0

Choose a tag to compare

@github-actions github-actions released this 10 Sep 15:12
fae9732

Binding.Worker is now Binding.Go, after errgroup.Group.Go and
sync.WaitGroup.Go, whose contract it has always had: run a function in a
goroutine the group tracks, cancel it when the group winds down, wait for it,
and let its error take the group down. go doc -all against 0.15.1 removes
Binding.Worker and adds Binding.Go with the same signature. An upgrade
breaks a caller that registers a worker
: rename the call from Worker to
Go, and nothing else changes.

Changed

  • Binding.Worker is renamed Binding.Go, with no alias left behind. The
    word "worker" still names what the method registers, in the docs and in the
    one error Stop reports about it, which now reads "worker did not return"
    rather than "Worker hook did not return".

v0.15.1

Choose a tag to compare

@github-actions github-actions released this 10 Sep 12:34
fc770df

A code-organisation release: the library is six files rather than one, and
the one observability gap the reorganisation turned up is closed. go doc -all against 0.15.0 changes doc comments only and no signature; dihttp and
dislog are untouched. An upgrade cannot break a caller.

Fixed

  • A panicking OnStart hook reports its EventStart, with the panic as
    Err, the way a panicking OnDrain or OnStop hook already reported
    theirs. Observers saw no start step at all for such a service; the failure
    still reached Start and Resolve as before.

v0.15.0

Choose a tag to compare

@floatdrop floatdrop released this 10 Sep 06:48

An application can say what it is doing. go doc -all against 0.14.0 adds one
field to Event, leaves every signature alone and leaves dihttp untouched;
dislog is a new package beside it. An upgrade cannot break a caller unless
it built an Event with an unkeyed composite literal.

Added

  • dislog, a new package that logs a scope's lifecycle events through
    log/slog: app.Observe(dislog.New(logger)) gives one line per constructor
    and per hook, so an application says what it is doing as it builds, starts,
    drains and stops. The event's kind is the message; the service, its scope,
    the module it came from and the duration are attributes. A step that failed
    logs at slog.LevelError with the error and the registration site, a step
    that succeeded at slog.LevelInfo or wherever dislog.Level puts it, and
    dislog.Site() logs the site every time. A service is named the way it is
    written in Go, with the import path lifted out into a pkg attribute. The
    package imports nothing beyond log/slog and di, so the library stays
    dependency-free and any handler will do; examples/ uses
    charmbracelet/log.
  • Event.Package, the import path of the type Event.Service names, so an
    observer can shorten a service name or group by its package without parsing
    one. It walks through pointers, since a pointer type is unnamed and carries
    no path of its own, and is empty for a key whose type is unnamed -- a
    []byte, a map[string]int -- because reflect already writes those with a
    short package name. An upgrade can break a caller only if it built an
    Event with an unkeyed composite literal, which go vet's composites check
    reports.

v0.14.0

Choose a tag to compare

@floatdrop floatdrop released this 07 Sep 14:44
d1e5c63

A module dependency report, derived from what registrations already carry.
go doc -all against 0.13.1 adds Scope.Modules and changes no signature;
an upgrade cannot break a caller.

Added

  • Scope.Modules() renders the modules registered into a scope and its
    ancestors: what each provides, what it needs and which module serves it,
    what it wraps, and which of its constructors are closures whose needs are
    known only when they run. A need only a resolving scope can provide is
    reported as owed, as Validate reports it, and a module's dependency on its
    own services is left out. It is derived from what registrations already
    carry, the module label and the parameters Wire declares, so there is
    nothing to declare twice. Keys are named by their package rather than their
    import path, to read beside the module labels.

v0.13.1

Choose a tag to compare

@floatdrop floatdrop released this 07 Sep 13:00
c444499

Three defects reported in #35, each with a reproduction, each real. go doc -all against 0.13.0 is unchanged in di and dihttp; an upgrade cannot
break a caller, and every fix turns a panic, a false rejection or a lost
error into the behaviour the documentation already promised.

Fixed

  • Wire and Wrap accepted a result merely assignable to the key, such as a
    chan int for a <-chan int key or a []byte for a named slice type, and
    then stored it as the constructor's own type, so Get panicked asserting
    it. The value is stored as the key's type now (#35).
  • Validate reported a cycle where a valid graph visited one Scoped
    binding in two scopes. A node on its path is now a binding in a holder, as
    it is on a resolution path at run time, so the two instances are told
    apart (#35).
  • A Worker that returned its own failure joined with the cancellation, as
    errors.Join(ctx.Err(), err), had the failure dropped with the
    cancellation, and Stop returned nil. Only an error that says nothing
    beyond the cancellation is dropped now (#35).

v0.13.0

Choose a tag to compare

@floatdrop floatdrop released this 06 Sep 17:50
7864772

One route, one line. go doc -all against 0.12.0 leaves di untouched and
adds dihttp.Handle; nothing changes shape or behaviour, and an upgrade
cannot break a caller.

Added

  • dihttp.Handle(method) makes an http.Handler that resolves a handler
    type from the request's scope and calls one of its methods, named by a
    method expression: mux.Handle("GET /users/{id}", dihttp.Handle((*Users).Show)).
    One type per resource with a method per route replaces a type, a
    registration and a closure per route. The type is Scoped when it needs
    the request and a plain singleton when it does not; Handle follows
    either. Nothing existing changes; an upgrade cannot break a caller.

v0.12.0

Choose a tag to compare

@floatdrop floatdrop released this 06 Sep 16:16
529bff2

The request-scope middleware becomes a dependency a server's constructor can
take, so an application needs no Provide closure to serve HTTP. go doc -all against 0.11.0 leaves di untouched and changes dihttp: Middleware
is now the type, NewMiddleware makes one, Module registers one. The rename
is the breaking change, and the reason for the minor bump.

Changed

  • dihttp.Middleware is now the type, func(http.Handler) http.Handler, so
    a server's constructor can take one as a parameter; the function that
    makes one is dihttp.NewMiddleware. A call dihttp.Middleware(app) no
    longer compiles: rename it, or take the middleware as a dependency.

Added

  • dihttp.Module registers a Middleware over the scope it is applied to.
    With it the guide's server is a wired constructor with its dependencies
    declared, and the guide application uses no Provide closure at all.

v0.11.0

Choose a tag to compare

@floatdrop floatdrop released this 06 Sep 15:50
3d6c4df

Validate no longer needs an adapter to check request scopes: the caller
says what such a scope will hold. go doc -all against 0.10.0 adds Stub
and Provided, gives Scope.Validate a variadic parameter, which every
existing call satisfies, and removes dihttp.Validate, the one breaking
change.

Added

  • di.Provided[T]() makes a Stub, a key the scope resolving a Scoped
    binding will provide. s.Validate(stubs...) then makes the check that scope
    would make: what the stubs cover is satisfied, and what neither the scope
    nor the stubs provide is an error rather than Owed. Stubs apply to the
    Scoped path only; a singleton that would build a Scoped service in its
    own scope still fails there, whatever a request scope holds.

Removed

  • dihttp.Validate, which opened a throwaway request scope to do what
    app.Validate(di.Provided[*http.Request]()) now does from the application
    scope, without an HTTP-shaped helper in the way. Replace the call with that
    expression and .Err().