scope

package
v0.0.0-...-eadd4a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package scope provides lifecycle management strategies for the IoC container. To add a custom lifecycle, implement the Scope interface in a new file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectRequestScopeStore

func InjectRequestScopeStore(r *http.Request) *http.Request

InjectRequestScopeStore attaches a fresh empty store to the request context at the start of each request. Called by Router.injectContext.

Types

type HttpRequestScope

type HttpRequestScope struct {
	// contains filtered or unexported fields
}

HttpRequestScope creates one instance per HTTP request. Distinct requests each get their own independent instance.

The unexported _ byte field makes this a non-zero-size struct. Without it, Go would point all instances to runtime.zerobase, making every *HttpRequestScope identical as a map key and causing different bindings to collide in the RequestScopeStore.

func NewHttpRequestScope

func NewHttpRequestScope() *HttpRequestScope

NewHttpRequestScope creates an HttpRequestScope. Each call returns a pointer with a unique address, used as the store key.

func (*HttpRequestScope) Resolve

func (s *HttpRequestScope) Resolve(ctx context.Context, factory func() any) any

type PrototypeScope

type PrototypeScope struct{}

PrototypeScope creates a new instance on every Resolve call.

func NewPrototypeScope

func NewPrototypeScope() *PrototypeScope

NewPrototypeScope creates a PrototypeScope.

func (*PrototypeScope) Resolve

func (s *PrototypeScope) Resolve(_ context.Context, factory func() any) any

type RequestScopeStore

type RequestScopeStore struct {
	// contains filtered or unexported fields
}

RequestScopeStore caches instances created by HttpRequestScope for a single HTTP request.

type Scope

type Scope interface {
	Resolve(ctx context.Context, factory func() any) any
}

Scope defines the lifecycle strategy for a registered dependency.

type SingletonScope

type SingletonScope struct {
	// contains filtered or unexported fields
}

SingletonScope creates exactly one instance for the lifetime of the application.

func NewSingletonScope

func NewSingletonScope() *SingletonScope

NewSingletonScope creates a SingletonScope.

func (*SingletonScope) Resolve

func (s *SingletonScope) Resolve(_ context.Context, factory func() any) any

type StoreKey

type StoreKey struct{}

StoreKey is the context key used to store and retrieve the RequestScopeStore.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL