PDA

View Full Version : Problem instantiating DAOs


snelson
02-07-2007, 12:03 AM
Hi

I'm using Spring.net latest source with nHibernate to integrate into an existing ASP.NET 2.0 app but having problems debugging some problems I'm having.

Just as a little background - I use Spring with Java at work so I know the basics with regards to how it works just having some problems using the .NET version.

I have an aspects.xml, services.xml and dao.xml referenced from web.config

My DAOs are defined as:


<object id="UserDao" type="iLogistics.Core.Data.HibernateUserDao, iLogisticsCore">
<property name="SessionFactory" ref="SessionFactory" />
</object>


My manager/service code is defined as:


<object id="UserManager" type="iLogistics.Core.Managers.UserManager, iLogisticsCore">
<property name="UserDao" ref="UserDao" />
</object>


The SessionFactory is defined as:


<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>iLogisticsCore</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
</dictionary>
</property>
</object>


And finally the dbprovider is defined as:

<db:dbProvider id="DbProvider" provider="SqlServer-2.0" connectionString="Data Source=${db.datasource};Database=${db.database};Tr usted_Connection=true" />


The DAO isn't getting injected into the Manager/Service. If you could give me a start to debug this I'd be most grateful.

Many thanks

snelson

BTW Really glad that Spring is available on .NET as this will help with testing and future expansion of the system. Thanks to the developers.

Erich Eichinger
02-07-2007, 09:00 AM
Hi snelson,


I'm glad you like Spring.NET. I hope we'll get your troubles out of the way asap ;-).

did you configure your web.config like shown here? Not using "WebContextHandler" instead of "DefaultContextHandler" in webapplications is one of the most common troubles.

You don't seem to get any errors, do you? Please check your context's objects by configuring the ContextMonitor handler as shown below:

<system.web>

<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
</httpHandlers>

<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
</system.web>



Calling ContextMonitor from your browser should show all objects in the context.


Where do you use the "UserManager" instance in your application? Does the UserManager get injected, but the UserManager's UserDao-property is unset?

try explicitely calling WebApplicationContext.Current.GetObject("UserDAO") from an .aspx page and look if you get a valid reference.

cheers,
Erich

snelson
02-07-2007, 09:58 PM
Hi Erich,

Many thanks for your super quick reply. As soon as you mentioned about where I'm using the UserManager I knew what I'd forgotten to include - dependency injection in my aspx pages. With this included I have success!

Sorry for my omission. I'm sure I'll be back with more questions shortly!

cheers

Stephen