Giter VIP home page Giter VIP logo

ioc's People

Contributors

berkaroad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ioc's Issues

The initialize function can specific another one, not just the default 'Initialize(XXX)'

When ioc.GetService[XXX]() to get singleton service, the exists service's implementation instance has already exists a function to initialize itself, but it's name is not 'Initilaize(XXX)'. Like this:

type Service1 interface{
    Field1() string
}

type ServiceImplemetation1 struct{
    field1 string
}

func (svc *ServiceImplemetation1) Init(svc2 *ServiceImplemetation2) {
    // the initialize function can be invoked when get service from ioc
    svc.field1 = svc2.Field1
}

func (svc *ServiceImplemetation1) Field1() string {
    return svc.field1
}

type ServiceImplemetation2 struct{
    Field1 string
}

ioc.AddSingleton[*ServiceImplemetation2](&ServiceImplemetation2{Field1:"my field1"})
ioc.AddSingleton[Service1](&ServiceImplemetation1{})
svc := ioc.GetService[Service1]()
println(svc.Field1())

replace exists service don't work well

container := ioc.New()
ioc.SetParent(anotherC)

// *eventsourcing.EventSourcedRepositoryBase[*Device] depends on  publishedstore.PublishedStore],
ioc.AddSingletonToC[publishedstore.PublishedStore](container, inmemoryps.Default())
ioc.AddSingletonToC[*eventsourcing.EventSourcedRepositoryBase[*Device]](container, &eventsourcing.EventSourcedRepositoryBase[*Device]{})

// replace exists service
ioc.AddSingleton[publishedstore.PublishedStore](&MySQLPublishedStore{})
// checking instance of publishedstore.PublishedStore in repo,
// but it still be instance of inmemoryps.InMemoryPublishedStore
repo := ioc.GetService[*eventsourcing.EventSourcedRepositoryBase[*Device]]()

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.