Code Monkey home page Code Monkey logo

Comments (2)

sarulabs avatar sarulabs commented on June 7, 2024 1

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.

ghstahl avatar ghstahl commented on June 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.