@@ -84,8 +84,8 @@ func (c *simpleCounter) GetCount() int {
8484 return c.counter
8585}
8686
87- func (c *simpleCounter ) New (ctx context .Context ) Counter {
88- return &simpleCounter{}
87+ func (c *simpleCounter ) New (ctx context .Context ) ( Counter , context . Context ) {
88+ return &simpleCounter{}, ctx
8989}
9090```
9191
@@ -169,18 +169,18 @@ import (
169169
170170func main () {
171171 // register
172- ore.RegisterLazyFunc [Counter](ore.Scoped , func (ctx context.Context ) Counter {
173- return &simpleCounter{}
172+ ore.RegisterLazyFunc [Counter](ore.Scoped , func (ctx context.Context ) ( Counter, context. Context ) {
173+ return &simpleCounter{}, ctx
174174 })
175175
176176 // OR
177- // ore.RegisterLazyFunc[Counter](ore.Transient, func(ctx context.Context) Counter {
178- // return &simpleCounter{}
177+ // ore.RegisterLazyFunc[Counter](ore.Transient, func(ctx context.Context) ( Counter, context.Context) {
178+ // return &simpleCounter{}, ctx
179179 // })
180180
181181 // Keyed service registration
182- // ore.RegisterLazyFunc[Counter](ore.Singleton, func(ctx context.Context) Counter {
183- // return &simpleCounter{}
182+ // ore.RegisterLazyFunc[Counter](ore.Singleton, func(ctx context.Context) ( Counter, context.Context) {
183+ // return &simpleCounter{}, ctx
184184 // }, "name here", 1234)
185185
186186 ctx := context.Background ()
@@ -220,8 +220,8 @@ func main() {
220220
221221 ore.RegisterLazyCreator [Counter](ore.Scoped , &yetAnotherCounter{})
222222
223- ore.RegisterLazyFunc [Counter](ore.Transient , func (ctx context.Context ) Counter {
224- return &simpleCounter{}
223+ ore.RegisterLazyFunc [Counter](ore.Transient , func (ctx context.Context ) ( Counter, context. Context ) {
224+ return &simpleCounter{}, ctx
225225 })
226226
227227 ore.RegisterLazyCreator [Counter](ore.Singleton , &yetAnotherCounter{})
@@ -260,8 +260,8 @@ import (
260260
261261func main () {
262262 // register
263- ore.RegisterLazyFunc [Counter](ore.Singleton , func (ctx context.Context ) Counter {
264- return &simpleCounter{}
263+ ore.RegisterLazyFunc [Counter](ore.Singleton , func (ctx context.Context ) ( Counter, context. Context ) {
264+ return &simpleCounter{}, ctx
265265 }, " name here" , 1234 )
266266
267267 // ore.RegisterLazyCreator[Counter](ore.Scoped, &simpleCounter{}, "name here", 1234)
@@ -281,10 +281,11 @@ func main() {
281281```
282282
283283## More Complex Example
284+
284285``` go
285286
286287type Numeric interface {
287- int
288+ int
288289}
289290
290291type GenericCounter [T Numeric ] interface {
@@ -316,8 +317,8 @@ import (
316317func main () {
317318
318319 // register
319- ore.RegisterLazyFunc [GenericCounter[int ]](ore.Scoped , func (ctx context.Context ) GenericCounter[int ] {
320- return &genericCounter[int ]{}
320+ ore.RegisterLazyFunc [GenericCounter[int ]](ore.Scoped , func (ctx context.Context ) ( GenericCounter[int ], context. Context ) {
321+ return &genericCounter[int ]{}, ctx
321322 })
322323
323324 // retrieve
@@ -336,25 +337,22 @@ goarch: amd64
336337pkg: github.com/firasdarwish/ore
337338cpu: 13th Gen Intel(R) Core(TM) i9-13900H
338339BenchmarkRegisterLazyFunc
339- BenchmarkRegisterLazyFunc-20 5404572 209.6 ns/op
340+ BenchmarkRegisterLazyFunc-20 4953412 233.5 ns/op
340341BenchmarkRegisterLazyCreator
341- BenchmarkRegisterLazyCreator-20 5683119 195.5 ns/op
342+ BenchmarkRegisterLazyCreator-20 5468863 231.3 ns/op
342343BenchmarkRegisterEagerSingleton
343- BenchmarkRegisterEagerSingleton-20 5335443 218.8 ns/op
344+ BenchmarkRegisterEagerSingleton-20 4634733 267.4 ns/op
344345BenchmarkGet
345- BenchmarkGet-20 4231207 279.8 ns/op
346+ BenchmarkGet-20 3766730 321.9 ns/op
346347BenchmarkGetList
347- BenchmarkGetList-20 2098818 544.6 ns/op
348+ BenchmarkGetList-20 1852132 637.0 ns/op
348349```
349350
350-
351351# Contributing
352352
353-
354- Feel free to contribute by opening issues, suggesting features, or submitting pull requests. We welcome your feedback and contributions.
355-
353+ Feel free to contribute by opening issues, suggesting features, or submitting pull requests. We welcome your feedback
354+ and contributions.
356355
357356# License
358357
359-
360358This project is licensed under the MIT License - see the LICENSE file for details.
0 commit comments