Comments (2)
Hello,
I think that what you want is implemented with the Unshared
field:
https://github.com/sarulabs/di/blob/master/definition.go#L10
It is not very well documented though. I'll see if I can improve it.
https://github.com/sarulabs/di#object-retrieval
By default the objects are shared that means what they stored as singletons in the Container. You will retrieve the exact same object every time you call the Get method on the same Container. The Build function will only be called once. In case when you don't want the objects to be shared set the Unshared property of object definition to true.
from di.
EDIT:
go get github.com/sarulabs/di/v2
in the code
import (
di "github.com/sarulabs/di/v2"
)
Saying that as a go newbie, what is
go get github.com/sarulabs/di
supposed to point to? Should it point to the latest v2 without me explicitly asking for it.
i.e. what is github.com/sarulabs/di v2.0.0 supposed to reference?
----
Nice, that is what I needed however what is published does not have that fix.
go mod init ditest
go get github.com/sarulabs/di
module ditest
go 1.16
require github.com/sarulabs/di v2.0.0+incompatible // indirect
definition.go
package di
// Def contains information to build and close an object inside a Container.
type Def struct {
Name string
Scope string
Build func(ctn Container) (interface{}, error)
Close func(obj interface{}) error
}
// DefMap is a collection of Def ordered by name.
type DefMap map[string]Def
// Copy returns a copy of the DefMap.
func (m DefMap) Copy() DefMap {
defs := DefMap{}
for name, def := range m {
defs[name] = def
}
return defs
}
from di.
Related Issues (15)
- Outside parameters for definition HOT 1
- Best way to go about passing/getting data from main package to another? HOT 1
- When using app.subcontainer is each one executed in it's own goroutine? HOT 2
- is it possible to Remove checkname from Add method ? HOT 12
- Great library design! 🚀 HOT 5
- How to use it in Gin HOT 2
- HTTPMiddleware returns http.HandlerFunc HOT 2
- Http.Request and http.responsewriter in container HOT 1
- Feature Request: Add by Type, GetByType and GetManyByType HOT 5
- Should I define severices for each main package HOT 4
- Memory leak when definition unshared true HOT 2
- Request Scope Isolation question
- Tags on v2 HOT 2
- Authentication middleware example HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di.