Documentation
¶
Index ¶
- Constants
- func AddScoped[T any](collection *ServiceCollection, provider func(s *Scope) any) error
- func AddSingleton[T any](collection *ServiceCollection, provider func(s *Scope) any) error
- func AddTransient[T any](collection *ServiceCollection, provider func(scope *Scope) any) error
- func GetService[T any](s *Scope) (T, error)
- type Scope
- type ServiceCollection
- type ServiceType
Constants ¶
const ( // SINGLETON lifetime represent to the services which will initialize once when requested // and same instance will be retrieved whenever requested again in the entire application. SINGLETON = iota // SCOPED lifetime represent to the services that will initialize in every new scope when requested // and same value will be retrieved in if the same scope requests it. // Note that requesting same service in different scopes will cause initializing new instance. SCOPED // TRANSIENT lifetime represent to the services that will initialize whenever requested. TRANSIENT )
Lifetimes
Variables ¶
This section is empty.
Functions ¶
func AddScoped ¶
func AddScoped[T any](collection *ServiceCollection, provider func(s *Scope) any) error
AddScoped registers a service as scoped
func AddSingleton ¶
func AddSingleton[T any](collection *ServiceCollection, provider func(s *Scope) any) error
AddSingleton registers a service as singleton
func AddTransient ¶
func AddTransient[T any](collection *ServiceCollection, provider func(scope *Scope) any) error
AddTransient registers a service as transient
func GetService ¶
GetService is responsible to retrieve or initialize requested service based on it's lifetime.
Types ¶
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is a struct to request services from service collection. Each scope has an isolated object pool for scoped services but will use a shared object pool singleton services. To initialize Scope struct please CreateScope method of ServiceCollection.
type ServiceCollection ¶
type ServiceCollection struct {
// contains filtered or unexported fields
}
ServiceCollection is collection of services to use them in your application. This struct contains two pools, first one for registered services and second one for provided singleton services. You may need to initialize ServiceCollection only one time in your application
func InitServiceCollection ¶
func InitServiceCollection() *ServiceCollection
InitServiceCollection initialize a service collection
func (*ServiceCollection) CreateScope ¶
func (collection *ServiceCollection) CreateScope() (*Scope, error)
CreateScope creates a new scope in application to retrieve services
func (*ServiceCollection) Lock ¶
func (collection *ServiceCollection) Lock()
Lock preparing service collection to create scope
type ServiceType ¶
type ServiceType struct {
// contains filtered or unexported fields
}
ServiceType used to store the configuration of the services in ServiceCollection