Results 1 to 8 of 8

Thread: DI without a framework

  1. #1
    Join Date
    Oct 2006
    Posts
    9

    Default DI without a framework

    Hi,
    I want to deploy an application heavily relies on DI, but dont want to set up the entire DI framework like Spring. I use a pretty simple method, to write all the dependency in a factory class, and get them by name when use.

    It is just hard code the relationship into a BeanFactory, are there any existed projects can read out the spring configuration file and generate such a BeanFactory with all the dependencies in it? So I can use it without to install a framework and the XML configuration file.

    Thanks!

    Regards,
    Sam Huang

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I'm not quite sure what you are trying to do here. Is there any chance you can explain a little more?
    Last edited by karldmoore; Aug 30th, 2007 at 07:44 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Oct 2006
    Posts
    9

    Default

    I use Spring Framework to manage the dependency during development, but when deployed to server side, it needs to do a lot of configuration in order to make it run. Instead, I build a factory to generate the beans in server, to simulate the function as Spring Framework.

    // the interface I get my dependencies from
    public interface MyBeanFactory {
    public Object getBean(String name) throws Exception;
    }

    // in server, i use this one to get object, they are hard coded
    public class SimpleBeanFactory implements MyBeanFactory {
    public Object getBean(String name) throws Exception{
    if(name.equalsIgnoreCase("hello"){return new Hello();}
    else ...
    }

    //in development, I use Spring to manage the dependency,
    public class SpringBeanFactory extends XmlBeanFactory implements MyBeanFactory {
    }

    I have the SimpleBeanFactory in server and use SpringBeanFactory in local to make use the XML configuration.

    My question is there any tool for generating SimpleBeanFactory here from the XML configuration so I dont need to deploy a framework to the server, instead I can use just a factory class to obtain all the dependencies?

    Thx!

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Quote Originally Posted by samhuang View Post
    My question is there any tool for generating SimpleBeanFactory here from the XML configuration so I dont need to deploy a framework to the server, instead I can use just a factory class to obtain all the dependencies?
    None that I know of. I'm not sure why you would even want to do this. Surely if you can use Spring in the development environment it would make sense to run with this?
    Last edited by karldmoore; Aug 30th, 2007 at 07:44 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #5
    Join Date
    Oct 2006
    Posts
    9

    Default

    It requires some process when you add a new 3rd party package or framework to the server side, so I wonder to add a bean factory as part of the code should be much more eaiser.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Quote Originally Posted by samhuang View Post
    It requires some process when you add a new 3rd party package or framework to the server side, so I wonder to add a bean factory as part of the code should be much more eaiser.
    I'm sorry I don't understand what you are getting at. You are using Spring to wire everything together, but when you deploy it you want to replicate what Spring does yourself. I don't see how this is easier.
    Last edited by karldmoore; Aug 30th, 2007 at 07:44 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  7. #7
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    I think I understand the issue. For whatever reasons, policy or resistence to Spring itself, one cannot just add Spring to an existing system.

    I did this once. I could not add Spring to a project, so I just created a property file that had the bean assignments, and a simple factory read it and exposed the beans via the getBean method. This is very common thing to do. What I did not do is try to reuse the Spring XML config file, and of course, did not try to duplicate full DI. I would not recommend having both Spring and a substitute in same project, would be a maintenance headache in future and besides will prevent taking advantage of advanced Spring features like AOP.

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Quote Originally Posted by jbetancourt View Post
    I think I understand the issue. For whatever reasons, policy or resistence to Spring itself, one cannot just add Spring to an existing system.
    I'm with you on this one, I understand the polictical problems as I've been there myself. What I don't understand is why you'd use it in development and then not in deployment. I would have thought it makes more sense to go with a general approach.

    Quote Originally Posted by jbetancourt View Post
    I would not recommend having both Spring and a substitute in same project, would be a maintenance headache in future and besides will prevent taking advantage of advanced Spring features like AOP.
    Indeed.
    Last edited by karldmoore; Aug 30th, 2007 at 07:44 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •