Chris Coleman
05-10-2007, 04:24 PM
Hi,
I'm new to spring and am currently using it with the NHibernate libraries prototyping a new version of a largeish WCF app I am designing. (It was great to see a release schedule for 1.1 :) )
Since I'm new to the Spring.NET framework then apologies if I've missed something painfully obvious.
I have some objects declared:
<object id="BugDAO" type="Brats.Data.DAO.NHibernate.NHibernateBugDAO, Brats.Data.DAO.NHibernate">
<property name="SessionFactory" ref="SessionFactory"/>
</object>
<object id="FindByIdCommand" type="Brats.Commands.FindByIdCommand, Brats.Commands" singleton="false">
<property name="BugDAO" ref="BugDAO" />
</object>
In essence its virtually identical to the Spring.Northwind demo in the examples folder.
The only difference being that I thought I'd try making my Business layer out of command objects, eg
public interface ICommand
{
object Execute();
void ValidateParameters();
}
public interface IFindByIdCommand
: ICommand
{
long BugId
{
get;
set;
}
}
public class FindByIdCommand
: IFindByIdCommand
{
private static ILog _logger = LogManager.GetLogger(typeof(FindByIdCommand));
#region Private members
private IBugDAO _BugDAO;
private long _bugId;
#endregion
#region Public properties
public IBugDAO BugDAO
{
get { return _BugDAO; }
set { _BugDAO = value; }
}
#endregion
#region Command Parameter properties
public long BugId
{
get { return _bugId; }
set { _bugId = value; }
}
#endregion
#region ICommand Members
[Transaction()]
public object Execute()
{
_logger.Debug(String.Format("Entering: {0}", MethodInfo.GetCurrentMethod().Name));
ValidateParameters();
Bug b = BugDAO.FindById(BugId);
return b;
}
public void ValidateParameters()
{
}
#endregion
}
Since the command objects store internal state then they will need to be prototype/non-singleton instances of the class. I figured that this would just be a case of changing the <object id="FindByIdCommand" tag to include singleton="false" as an attribute.
However setting this causes a NullReferenceException to be called on L141 of the file ControlFlowFactory.cs (method.DeclaringType throws an System.ArgumentNullException), and then an ObjectCreationException on L752 of AbstractAutoeireObjectFactory.cs.
I'm totally out of ideas now any and any help would be much appreciated.
Thanks
Chris
I'm new to spring and am currently using it with the NHibernate libraries prototyping a new version of a largeish WCF app I am designing. (It was great to see a release schedule for 1.1 :) )
Since I'm new to the Spring.NET framework then apologies if I've missed something painfully obvious.
I have some objects declared:
<object id="BugDAO" type="Brats.Data.DAO.NHibernate.NHibernateBugDAO, Brats.Data.DAO.NHibernate">
<property name="SessionFactory" ref="SessionFactory"/>
</object>
<object id="FindByIdCommand" type="Brats.Commands.FindByIdCommand, Brats.Commands" singleton="false">
<property name="BugDAO" ref="BugDAO" />
</object>
In essence its virtually identical to the Spring.Northwind demo in the examples folder.
The only difference being that I thought I'd try making my Business layer out of command objects, eg
public interface ICommand
{
object Execute();
void ValidateParameters();
}
public interface IFindByIdCommand
: ICommand
{
long BugId
{
get;
set;
}
}
public class FindByIdCommand
: IFindByIdCommand
{
private static ILog _logger = LogManager.GetLogger(typeof(FindByIdCommand));
#region Private members
private IBugDAO _BugDAO;
private long _bugId;
#endregion
#region Public properties
public IBugDAO BugDAO
{
get { return _BugDAO; }
set { _BugDAO = value; }
}
#endregion
#region Command Parameter properties
public long BugId
{
get { return _bugId; }
set { _bugId = value; }
}
#endregion
#region ICommand Members
[Transaction()]
public object Execute()
{
_logger.Debug(String.Format("Entering: {0}", MethodInfo.GetCurrentMethod().Name));
ValidateParameters();
Bug b = BugDAO.FindById(BugId);
return b;
}
public void ValidateParameters()
{
}
#endregion
}
Since the command objects store internal state then they will need to be prototype/non-singleton instances of the class. I figured that this would just be a case of changing the <object id="FindByIdCommand" tag to include singleton="false" as an attribute.
However setting this causes a NullReferenceException to be called on L141 of the file ControlFlowFactory.cs (method.DeclaringType throws an System.ArgumentNullException), and then an ObjectCreationException on L752 of AbstractAutoeireObjectFactory.cs.
I'm totally out of ideas now any and any help would be much appreciated.
Thanks
Chris