PDA

View Full Version : Why does Spring don't inject object to my apsx pages?



Tommy_Shen
11-16-2006, 02:17 AM
hi, all
same as the title. I think I configurate the web.config correctly, but Spring doesn't inject object to my aspx pages. I saw that Spring WebApplicationContext had loaded my aspx page object in logfile, and I could get the object if I code in my aspx.cs source file like :


IApplicationContext ctx = ContextRegistry.GetContext();
memberDao = ctx["MemberDAO"] as IMemberDAO;

but miss DI, why?

configuration snippet:
Web.Config


...
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
...
<context>
<resource uri="assembly://DDA.GA.Business/DDA.GA.Business.Context/applicationContext-Business.xml"/>
<resource uri="assembly://DDA.GA.Business/DDA.GA.Business.Context/applicationContext-Db.xml"/>
<resource uri="~/Context/applicationContext-Web.xml"/>
</context>

applicationContext-Web.xml:


<objects xmlns="http://www.springframework.net" default-autowire="byName">
<object id="DefaultPage" type="~/Default.aspx"/>
</objects>

Bruno Baia
11-16-2006, 09:41 AM
Hi,





<objects xmlns="http://www.springframework.net" default-autowire="byName">
<object id="DefaultPage" type="~/Default.aspx"/>
</objects>



The problem here is that you overrided the id, so your "injected" page will be available @ DefaultPage.aspx

Don't define the id :


<objects xmlns="http://www.springframework.net" default-autowire="byName">
<object type="~/Default.aspx"/>
</objects>



Hope this helps,
Bruno

Tommy_Shen
11-16-2006, 11:46 AM
but, it works now.