Both GetWithPairs and GetWith allow you to pass temporary dependencies that will only be available during the
retrieval. This is particularly useful for factory binds that need additional context or runtime values that aren’t
registered in the main injector.
GetWithPairs
GetWithPairs allows you to pass temporary dependencies as a slice of BindEntry. This is convenient when you
have a fixed set of values to inject.
The type key is automatically generated from the value’s type, so you don’t need to manually specify it. Use
remy.NewBindEntry[T](value) for values without tags, or remy.NewBindEntryTagged[T](value, tag) for values that
need a tag.
GetWith uses a callback function to register temporary dependencies. This approach provides more flexibility and
allows you to perform additional setup logic within the callback.
typeRequestHandlerstruct{RequestIDstringUserIDintDB*sql.DB}// Factory bind that requires temporary contextremy.Register(injector,remy.Factory(func(retrieverremy.DependencyRetriever)(*RequestHandler,error){requestID:=remy.MustGet[string](retriever,"request-id")userID:=remy.MustGet[int](retriever,"user-id")db:=remy.MustGet[*sql.DB](retriever)return&RequestHandler{RequestID:requestID,UserID:userID,DB:db,},nil},),)// Later, when handling a requesthandler:=remy.MustGetWith[*RequestHandler](injector,func(injectorremy.Injector)error{remy.RegisterInstance(injector,generateRequestID(),"request-id")remy.RegisterInstance(injector,currentUserID,"user-id")returnnil},)
Conditional Registration
You can use the callback to conditionally register dependencies: