Arguing at a wedding: Why I couldn’t just keep quiet DebateWatch: Boring, and WHAT ABOUT THE ENVIRONMENT!
Oct 13

Let’s leak IoC/DI into standards. You miss them when they aren’t there!

Tech Add comments

After working with a DI container such as Spring, Pico, or HiveMind, it is hard to look back.

However, the real world means that you often can’t just be playing in the sand box with your DI container. You have to talk to the big kids who don’t play as nice.

I run into this all of the time when working on a web application where I need to do something such as setup a <listener>

You have to say in the web.xml:

<listener>
<listener-class>myproject.ContextLoaderListener</listener-class>
</listener>

Ok, so now I have got a listener, I may want it to do something. Chances are that I want it to talk to a service that I already have to do that thing. Fortunately, I can grab the context for the container and query for services that I want:

public void contextDestroyed(ServletContextEvent event) {
ApplicationContext appContext =
WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());

CacheManager cm = (CacheManager) appContext.getBean("cacheManager");
cm.shutdown();
}

This is OK. It is a lot better than having to have: CacheManager cm = new MyParticullarCacheManager(); However this isn’t ideal.

I would love to see DI leaking into standards. E.g seeing something in the web.xml like:

<listener>
<listener-class>myproject.ContextLoaderListener</listener-class>
<property name="cacheManager">spring:cacheManager</property>
</listener>

It would be really cool to define prefixes such as spring, hivemind, pico, etc… which can tie to that particular container. Or, there could be another place where you plugin the container and the web.xml would go to those services to look up the cacheManager.

2 Responses to “Let’s leak IoC/DI into standards. You miss them when they aren’t there!”

  1. jozy Says:

    do not trouble trouble till trouble troubles you

  2. Curobertillo Says:

    Hi there! it’s the best site of 14357

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'ajax'