Session is unexpectedly closed?

593 peržiūros
Praleisti ir pereiti prie pirmo neskaityto pranešimo

marcus

neskaityta,
2010-10-04 13:09:292010-10-04
kam: 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

neskaityta,
2010-10-04 16:28:312010-10-04
kam: 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

neskaityta,
2010-10-05 02:59:022010-10-05
kam: 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

neskaityta,
2010-10-05 08:11:402010-10-05
kam: 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

neskaityta,
2010-10-05 12:22:082010-10-05
kam: 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
Atsakyti visiems
Atsakyti autoriui
Persiųsti
0 naujų pranešimų