Alright, so I tracked down the culprit. It wasn't immediately obvious.
I use AutoMapper to map DTO to Domain and back. This, apparently, was bad practice.
My logic looked something like:
- Application_Start
- AutofacRegistrations.RegisterAndSetResolver
- AutoMapper.SetMappings
Inside of SetMappings, I needed access to my DAO factory in order to map my DTO back to a Domain: AutoMapper best practices - Should I be asking the DAO for information to fulfill mapping from DTO to domain object?
In asked DependencyResolver for my DaoFactory. This is where the problem arose. I was asking for a DaoFactory before Autofac had a chance to create a session for my current request (since I wasn't IN a request yet.) This caused it to generate an ISession prematurely in order to be able to dish out a DaoFactory.
Refactoring my code such that each Domain object was responsible for re-mapping resolved the issue. Something like:
public static PlaylistItem Create(PlaylistItemDto playlistItemDto, IPlaylistManager playlistManager)
{
PlaylistItem playlistItem = new PlaylistItem
{
Cid = playlistItemDto.Cid,
Id = playlistItemDto.Id,
Playlist = playlistManager.Get(playlistItemDto.PlaylistId),
Sequence = playlistItemDto.Sequence,
Title = playlistItemDto.Title,
Video = Video.Create(playlistItemDto.Video)
};
return playlistItem;
}
where I've used IoC to give the IPlaylistManager to the PlaylistItem instead of getting access to it through DependencyResolver.