Comments (5)
Thanks a lot @dtitov I updated my project and now it works. :)
The thing I didn't understand / miss in the doc is the fact that di
creates an instance automatically.
Really good job for the library.
from di.
Hi @Dudesons,
Thanks for trying out the library. Right away, I see one issue with your code:
_, err = di.RegisterBeanInstance(k, v)
This is not how you should register your repos. Instead, you should register them by class, i.e.:
_, _ = di.RegisterBean("UserRepository", reflect.TypeOf((*repository.UserRepository)(nil)))
_, _ = di.RegisterBean("CommunicationRepository", reflect.TypeOf((*repository.CommunicationRepository)(nil)))
_, _ = di.RegisterBean("AuthRepository", reflect.TypeOf((*repository.AuthRepository)(nil)))
Otherwise, you are just creating empty structs and registering them as beans, so injection won't happen.
from di.
Ok, I have another question about that:
_, _ = di.RegisterBean("UserRepository", reflect.TypeOf((*repository.UserRepository)(nil)))
_, _ = di.RegisterBean("CommunicationRepository", reflect.TypeOf((*repository.CommunicationRepository)(nil)))
_, _ = di.RegisterBean("AuthRepository", reflect.TypeOf((*repository.AuthRepository)(nil)))
I have a doubt on how can I register an instance of one my object, because when I read the README at this section: https://github.com/goioc/di#beans-registration on Using pre-created instance
, seems to match my need but if I correctly understand you it doesn't work with the inject.
from di.
By "pre-created" instance, I meant the self-sufficient instance that doesn't need any injections to it, let's say string
or other dependency-less struct. If you need injections to be done, then you should use RegisterBean
- and di
will create an instance for you automatically + will inject the dependencies :)
from di.
I'm glad that it helped :)
from di.
Related Issues (15)
- [Bug report]
- [Feature request] HOT 2
- Improve beans initialization HOT 2
- [Feature request] register&inject bean with named group HOT 6
- [Feature request] when the Prototype bean destroy? HOT 3
- postconstruct does not support dependency, postconstruct executes random HOT 10
- Question regarding the implmentation of PostConstruct HOT 1
- Been Injection Not Working HOT 2
- [Feature request]Circular dependency HOT 1
- [Bug report] Can't get another bean instance from bean factory, despite of the docs HOT 5
- [Feature request] Add examples about how to use this library HOT 1
- replace ioutil.ReadAll with io.ReadAll in README HOT 1
- [Feature request] Autowiring beans into slice or map depending on the interface HOT 6
- [Feature request] Bean lifecycle 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.