berkaroad / ioc Goto Github PK
View Code? Open in Web Editor NEWmove to https://github.com/gopkg-berkaroad-top/ioc
Home Page: https://github.com/gopkg-berkaroad-top/ioc
License: MIT License
move to https://github.com/gopkg-berkaroad-top/ioc
Home Page: https://github.com/gopkg-berkaroad-top/ioc
License: MIT License
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())
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]]()
ioc.Inject(func(param1 int, param2 string, param3 struct{Field1 string}, param4 *struct{Field1 string}) {
// suggest don't panic, just use zero value to invoke the function
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.