Coder Social home page Coder Social logo

Comments (6)

mnesarco avatar mnesarco commented on August 24, 2024

HI @Juchar
How many environments do you have in your App?

In terms of mapper injection, this:

@Inject 
@Environment("env1")
UserMapper userMapper;

Is not so different from this:

@Inject 
@Named("env1")
UserMapper userMapper;

And in terms of the producer, this is not a big deal:

@Produces
@Named("env1")
@SessionFactoryProvider
public SqlSessionFactory produceFactory1() {
  return produceFactory("env1");
}

@Produces
@Named("env2")
@SessionFactoryProvider
public SqlSessionFactory produceFactory2() {
  return produceFactory("env2");
}

You can also use your own Qualifier annotation, as soon as you use a producer method per Environment.

I don't know your implementation details but I suppose there are few environments. But if you have so many environments (something like more than 10) then it is a different story, but Environments are static anyway so I don't see the use case but please elaborate more to continue the discussion.

Thanks.

from cdi.

mnesarco avatar mnesarco commented on August 24, 2024

@hazendaz what do you think about this issue?

from cdi.

hazendaz avatar hazendaz commented on August 24, 2024

Not sure the benefit here. I generally have my environmental information separated from the code so I'm basically only injecting in what I actually need for any given environment with a system property to tell me what specific file to read and use. That may not be entirely cloud ready solution but not sure about using it in this way. Unfortunately I have not gotten far enough at my day job to finally start using mybatis-cdi over our home grown solution due to changing priorities and the code being given off to another team I only occassionally get to help. I might have a better opinion in a couple months given I've recently been pulled back in a bit.

from cdi.

hazendaz avatar hazendaz commented on August 24, 2024

And I must says the added backwards compatibility that is now present which was the primary holdup on switching over sooner.

from cdi.

Juchar avatar Juchar commented on August 24, 2024

I will give a little bit more detailed information about the use case I have, maybe it's more easy to understand.

We have a project that consists of several sub-projects, possibly all connecting to different environments (so not Prod, Dev, Test, etc.).

As we wanted simplify the handling we thought about a determined place to put the different configuration.xml files inside the classpath.

We then merge those to a big configuration.xml and let the application inject the according mappers by just using a qualifier with their environment as an argument (e.g. @Environment("ABC")).

That way it is not needed that an application provides an own producer and the configuration handling would be centralized at a single point.

This would be quite easy by using a @NonBindinding field inside the qualifier and use the InjectionPoint as a method parameter of the producer.

The big problem we faced is that mybatis already registers various mapper beans at startup and we can't access the injection point and therefore not use the qualifiers parameter inside the producer that constructs the session factory.

from cdi.

mnesarco avatar mnesarco commented on August 24, 2024

Hi @Juchar , I am sorry. This feature won't be included any time soon. Y Suggest you to create a fork and do some experiments, then if you want you can contribute any enhancement via a PR.

from cdi.

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.