Coder Social home page Coder Social logo

Injecting beans by name about mongock HOT 4 CLOSED

thorstenvogel avatar thorstenvogel commented on June 11, 2024
Injecting beans by name

from mongock.

Comments (4)

dieppa avatar dieppa commented on June 11, 2024

Hello @thorstenvogel ,

can you tell me which version are you using, please?

from mongock.

thorstenvogel avatar thorstenvogel commented on June 11, 2024

Hi @dieppa, using latest and greatest 5.3.4 :)

I managed to get it to work by defining my own MongockApplicationRunner using MongockSpringboot.builder() and registering the dependencies manually by name.

So i am missing out of the configuration magic that @EnableMongock provides.

My goal was to inject dependencies via their name into ChangeUnits - and i couldn't figure out another way.

EDIT:
My approach does not work, so the question remains.

from mongock.

thorstenvogel avatar thorstenvogel commented on June 11, 2024

I managed to inject my named beans into ChangeUnit-Methods via

    @Execution
    public void migrateSomething(@NonLockGuarded
                                                      @Named("namedBean")
                                                      MyBean namedBean) {
        // do something with namedBean
    }

The injection mechanism in Mongock does not allow fields to be injected into the class as constructor-parameter as far as i can see.

For the future ist would be great if ChangeUnits could just be Spring beans, utilizing the dependency-injection mechanisms of Spring.

from mongock.

dieppa avatar dieppa commented on June 11, 2024

Hello, I didn't answer until now as we have been pretty busy and I saw you managed to make it work.

Your suggestion is very interesting, but represents important challenges, specially because Mongock proxies the injection for distributed synchronisation's sake.

On the other hand, I don't think it's that far. As long as I remember, springboot supports @Named injections and Mongock should support dependency injection as construction time.

Thanks!

from mongock.

Related Issues (20)

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.