Code Monkey home page Code Monkey logo

Comments (5)

Dudesons avatar Dudesons commented on June 15, 2024 1

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.

dtitov avatar dtitov commented on June 15, 2024

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.

Dudesons avatar Dudesons commented on June 15, 2024

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.

dtitov avatar dtitov commented on June 15, 2024

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.

dtitov avatar dtitov commented on June 15, 2024

I'm glad that it helped :)

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.