I'm trying to build a website using C# MVC nHibernate. All works well, but when i navigate my website in multiple browsers i get the error:
There is already an open DataReader associated with this Connection which must be closed first.
I have binded many of my services to one session (ISession).
//ContentService Bingings
Bind<IContentService>().To<ContentService>().InRequestScope();
Bind<ISession>()
.ToMethod(
context =>
context.Kernel.Get<IMasterSessionSource>()
.ExposeConfiguration()
.BuildSessionFactory()
.OpenSession()
)
.WhenInjectedInto<IContentService>()
.InSingletonScope();
//GeneralService Bindings
Bind<ISession>()
.ToMethod(
context =>
context.Kernel.Get<IMasterSessionSource>()
.ExposeConfiguration()
.BuildSessionFactory()
.OpenSession())
.WhenInjectedInto<IGeneralService>()
.InSingletonScope();
Bind<IGeneralService>()
.To<GeneralService>()
.InSingletonScope();
//CrossSellService Bindings
Bind<ISession>()
.ToMethod(
context =>
context.Kernel.Get<IMasterSessionSource>()
.ExposeConfiguration()
.BuildSessionFactory()
.OpenSession())
.WhenInjectedInto<ICrossSellService>()
.InSingletonScope();
Bind<ICrossSellService>()
.To<CrossSellService>()
.InSingletonScope();
//Details Bindings
Bind<ISession>()
.ToMethod(
context =>
context.Kernel.Get<IMasterSessionSource>()
.ExposeConfiguration()
.BuildSessionFactory()
.OpenSession())
.WhenInjectedInto<IDetailsService>()
.InRequestScope();
Bind<IDetailsService>()
.To<DetailsService>()
.InRequestScope();
and they get called for other uses. for example my DetailsService:
public interface IDetailsService
{
//OVERRIDES HERE;
}
public class DetailsService : IDetailsService
{
private static IContentService Context { get; set; }
public DetailsService(IContentService context)
{
Context = context;
}
...
where IContentService is my main Query class:
public interface IContentService
{
IQueryable<Source> Sources { get; }
}
public class ContentService : IContentService
{
private readonly ISession _session;
public ContentService(ISession session)
{
_session = session;
}
public IQueryable<Source> Sources
{
get { return _session.Query<Source>(); }
}
not sure why its not accessing multiple queries