關於jdon的ioc的入門問題

deyami發表於2009-05-26

示例中有如下一段程式碼

public class TestServicePOJOImp implements TestService, Poolable{
   private JdbcDAO jdbcDao;
   public TestServicePOJOImp(JdbcDAO jdbcDao) {
         this.jdbcDao = jdbcDao;
   }
   public void createUser(EventModel em) {
      ....
   }
 }


配置檔案中是這樣寫的

<app>
   <services>
      <pojoService name="testService" class="com.jdon.framework.test.service.TestServicePOJOImp"/>

      <!-- 新增加的配置:jdbcDAO是被TestServiceImp呼叫的,是為其服務的。 -->
      <component name="jdbcDAO" class="com.jdon.framework.test.dao.JdbcDAO"/>
   </services>
</app>
<p class="indent">


請問,
TestService testService = (TestService) WebAppUtil.getService("testService ", request);
當我獲取bean的時候,component jdbcDAO是怎樣被注入到testService中的?是將jdbcDAO作為testService的構造引數嗎?還是直接為private JdbcDAO jdbcDao欄位賦值?

還有個小問題,

<services>
		<pojoService name="forumService" class="com.jdon.jivejdon.service.imp.ForumServiceImp"/>		
		<pojoService name="accountService" class="com.jdon.jivejdon.service.imp.account.AccountServiceImp"/>
		<pojoService name="accountProfileService" class="com.jdon.jivejdon.service.imp.account.AccountProfileServiceImp"/>
		
		<pojoService name="forumMessageService" class="com.jdon.jivejdon.service.imp.message.ForumMessageShell"/>	
     	<pojoService name="forumMessageQueryService" class="com.jdon.jivejdon.service.imp.message.ForumMessageQueryServiceImp"/>
     	<pojoService name="uploadService" class="com.jdon.jivejdon.service.imp.upload.UploadServiceShell"/>
     	
     	<pojoService name="shortMessageService" class="com.jdon.jivejdon.service.imp.shortmessage.ShortMessageServiceImp"/>
     	<pojoService name="shortMessageQueryService" class="com.jdon.jivejdon.service.imp.shortmessage.ShortMessageQueryServiceImp"/>
     	
     	
     	
		<component name="messageKernel" class="com.jdon.jivejdon.service.imp.message.MessageKernel"/>
		<component name="messageRenderingFilter" class="com.jdon.jivejdon.service.imp.message.MessageRenderingFilter"/>
		<component name="containerUtil" class="com.jdon.jivejdon.service.util.ContainerUtil"/>
        <component name="sessionContextUtil" class="com.jdon.jivejdon.service.util.SessionContextUtil"/>	
	</services>


如果確實是透過構造引數注入的話,jdon的配置檔案中好像並未強制要求 component節點作為pojoService 節點的屬性,
那麼對於下面的這種構造引數過多的類,造成配置檔案過於雜亂,不便於開發?

public ForumRepository(ForumDao forumDao,MessageRepository messageRepository,ForumBuilder forumBuilder){
		this.forumDao = forumDao;
		this.messageRepository = messageRepository;
		this.forumBuilder = forumBuilder;
	}

相關文章