Session is unexpectedly closed?

595 vistas
Ir al primer mensaje no leído

marcus

no leída,
4 oct 2010, 1:09:29 p.m.4/10/2010
para structuremap-users
I use this approuch
http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/
for setting up fnh with structuremap but after one request I get the
following exception
Session is closed! Object name: 'ISession'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.ObjectDisposedException: Session is closed!
Object name: 'ISession'.

My repository class looks like this:

public class Repository : IRepository {
private readonly ISession _session;
public Repository(ISession session) {
_session = session;
}
public T Get<T>(Expression<Func<T, bool>> predicate) {
return
_session.CreateCriteria(typeof(T)).Add(predicate).UniqueResult<T>();
}
and I register my repository in structuremap like this:

public class RepositoryRegistry : Registry {
public RepositoryRegistry() {
Scan(a => {
a.AssembliesFromApplicationBaseDirectory();
a.AddAllTypesOf<IRepository>();
});
}
}
How can I prevent the session from being closed?

The error seems to occur in my sitemapprovider. Because the
constructor must have an empty default constructor I use
ObjectFactory.GetInstance<IRepository>() in the constructor and that
seems to be the problem?

public class MvcSiteMapProvider : SiteMapProvider {
private IRepository _repository;
public MvcSiteMapProvider() {
_repository = ObjectFactory.GetInstance<IRepository>();
}
}

This is the output from ObjectFactory.WhatDoIHave() pastebin.com/
57dRSR8m

Elliott O'Hara

no leída,
4 oct 2010, 4:28:31 p.m.4/10/2010
para structure...@googlegroups.com
Yeah, the sitemap is a singleton, and the ISession is only set once, so once it's disposed (EndRequest) you're getting the error.

I think if you expose it as a static property and and use ObjectFactory.BuildUp in BeginRequest -- or just don't use SiteMap :)


--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To post to this group, send email to structure...@googlegroups.com.
To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/structuremap-users?hl=en.


marcus

no leída,
5 oct 2010, 2:59:02 a.m.5/10/2010
para structuremap-users
I'm no fan of the sitemap, but it may work for a while.

You mean like this?

protected void Application_BeginRequest() {
var repository = ObjectFactory.GetInstance<IRepository>();
Stormbreaker.Core.Web.MvcSiteMapProvider.Repository =
repository;
ObjectFactory.BuildUp(repository);
}

On Oct 4, 10:28 pm, "Elliott O'Hara" <elliott.oh...@gmail.com> wrote:
> Yeah, the sitemap is a singleton, and the ISession is only set once, so once
> it's disposed (EndRequest) you're getting the error.
>
> I think if you expose it as a static property and and use
> ObjectFactory.BuildUp in BeginRequest -- or just don't use SiteMap :)
>
>
>
> On Mon, Oct 4, 2010 at 12:09 PM, marcus <mar...@meridium.se> wrote:
> > I use this approuch
>
> >http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-wit...
> > structuremap-us...@googlegroups.com<structuremap-users%2Bunsubs cr...@googlegroups.com>
> > .

Elliott O'Hara

no leída,
5 oct 2010, 8:11:40 a.m.5/10/2010
para structure...@googlegroups.com
Sorry, 
If you just make it an instance property, BuildUp should work for you - no need for the singleton.



-- Sent from my Palm Pre


To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.

Robin Clowers

no leída,
5 oct 2010, 12:22:08 p.m.5/10/2010
para structuremap-users
Hey Marcus, I gave a more complete example on your StackOverflow
question: http://stackoverflow.com/questions/3833243/setting-up-fluent-nhibernate-and-structuremap-for-a-web-application

On Oct 5, 5:11 am, "Elliott O'Hara" <elliott.oh...@gmail.com> wrote:
> Sorry,
> If you just make it an instance property, BuildUp should work for you - no
> need for the singleton.
>
> -- Sent from my Palm Pre
>
> ------------------------------
> > > structuremap-us...@googlegroups.com<structuremap-users%2Bunsubs cr...@googlegroups.com><structuremap-users%2Bunsubs
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos