I seperate my domain logic from my web service logic
This is from my domain and actually gets the data from nHibernate
public static IList<Location> LoadReturnLocationsFromDatabase(DateTime lastUpdateTime)
{
using (var session = NHibernateHelper.OpenSession())
{
// retreive all stores and display them
using (session.BeginTransaction())
{
var locations = session.CreateCriteria(typeof(Location)).Add(Expression.Gt("LastUpdatedTime", lastUpdateTime)).SetMaxResults(10).List<Location>();
return locations;
}
}
}
This data is then returned to the web service and I use Automapper to duplicate it, so as to not expose the database access object to the web service and keep all things seperate.
public IList<GetLocationDetailsResponse> GetLocationUpdate(DateTime lastUpdateTimeDT)
{
Mapper.CreateMap<Location, GetLocationDetailsResponse>();
IList<Location> locations = WhygoDomain.GetLocations.LoadReturnLocationsFromDatabase(lastUpdateTimeDT);
IList<GetLocationDetailsResponse> getLocationDetails = Mapper.Map<IList<Location>, IList<GetLocationDetailsResponse>>(locations);
return getLocationDetails;
}
My problem is that I can't do the mapping unless I specify that the relationship between location and state isn't lazy loaded because the web service is outside:
using (var session = NHibernateHelper.OpenSession())
in the data domain.
Lazy loading does seem to be the prefered method of doing something like this, so I'm wondering if this approach ok? This is a data export service which will export so memory usage etc could end up being problematic.
If I need to change this, is the cause of the problem the structure of my code? If so how can I keep my domain logic seperate, and get around this problem?