Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Component Lifestyle advice
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steven  
View profile  
 More options Feb 13 2012, 9:23 am
From: Steven <reachsoftw...@gmail.com>
Date: Mon, 13 Feb 2012 06:23:30 -0800 (PST)
Local: Mon, Feb 13 2012 9:23 am
Subject: Component Lifestyle advice
Hi,

I'm looking for some advice on how to best configure this situation.
I have the following components in an ASP MVC application.

Controllers - Transient by requirement of MVC
Services - Controllers call these to get to the business layer
Validators - Services use these to validate components.  These are
expensive to create so I need them to be Singleton
Repositories - Services and Validators use these to access data
ISession - NHibernate Session configured as PerWebRequest

I'm looking at how best to configure Services and Repositories.  On
the surface it seems like they could both be configured the same.
Repositories only dependency (passed in on the constructor) is
ISession.  Services only dependencies (passed in on the constructor)
are Repositories.  When a Service needs a Validator it gets it from
the ServiceLocator.  Validators get Repositories in the constructor.
I think that because Validators are Singleton passing Transient
Repositories is problematic because the Validator will hold onto a
Repository that has a disposed ISession.

Any help here would be greatly appreciated.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kelly Leahy  
View profile  
 More options Feb 13 2012, 9:45 pm
From: Kelly Leahy <kelly.p.le...@gmail.com>
Date: Mon, 13 Feb 2012 18:45:37 -0800
Local: Mon, Feb 13 2012 9:45 pm
Subject: Re: Component Lifestyle advice

Your services and/or repositories must be configured PerWebRequest if they
are using ISession.  Otherwise, they'll not get recreated with different
sessions (i.e. they will get created once, on the first time a controller
that uses them is resolved and never recreated with the new sessions).

Since your validators use repositories to access data, they then also need
to be PerWebRequest.  Given the cost you mention that it takes to create
them, you'll need to rethink something.  One way to fix the problem is to
make the repository dependency come in through a parameter to the Validator
objects, so that it can be supplied dynamically.  Another way would be to
extract the costly part of the validator into a singleton service that is
used by the validators, and allow the validators to be created
PerWebRequest, with the expensive part being singletons.

As you mentioned in your message, IDisposable is a problem too, where you
need things with IDisposable to have "similar" lifetimes to their users.

Another approach might be to have a "SessionProvider" or "SessionAccessor"
that is a factory-like object that provides the session from the container
by doing a container.Resolve<ISession>().  On the first call for a web
request, this should create the session, and on later calls, it should
return the same session already created.  Unfortunately, you'll have to
figure out how to do the container.Release() that goes with the Resolve, or
else you'll have a memory leak.  Hopefully someone else will give some more
ideas.

Kelly


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jordan  
View profile  
 More options Feb 14 2012, 11:23 am
From: Jordan <augustusgor...@yahoo.co.uk>
Date: Tue, 14 Feb 2012 08:23:59 -0800 (PST)
Local: Tues, Feb 14 2012 11:23 am
Subject: Re: Component Lifestyle advice

> Another approach might be to have a "SessionProvider" or "SessionAccessor"
> that is a factory-like object that provides the session from the container
> by doing a container.Resolve<ISession>().  On the first call for a web
> request, this should create the session, and on later calls, it should
> return the same session already created.  Unfortunately, you'll have to
> figure out how to do the container.Release() that goes with the Resolve, or
> else you'll have a memory leak.  Hopefully someone else will give some more
> ideas.

Why not put the ISessionFactory in the container, and then create the
ISession at the start of the web request. Any code that needs access
to the current ISession can call GetCurrentSession() on the session
factory.

Isn't this pretty much how castle always used to work?

regards,
Jordan.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hammett  
View profile  
 More options Feb 14 2012, 2:39 pm
From: hammett <hamm...@gmail.com>
Date: Tue, 14 Feb 2012 11:39:44 -0800
Local: Tues, Feb 14 2012 2:39 pm
Subject: Re: Component Lifestyle advice
I'd prefer that as well.

Anyways, if there's something I regret is these customs lifestyle
managers. We should be good with singleton/transient for 99.9% of
situations. Well, maybe on Windsor 4...

--
Cheers,
hammett
http://hammett.castleproject.org/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kelly Leahy  
View profile  
 More options Feb 14 2012, 3:57 pm
From: Kelly Leahy <kelly.p.le...@gmail.com>
Date: Tue, 14 Feb 2012 12:57:43 -0800
Local: Tues, Feb 14 2012 3:57 pm
Subject: Re: Component Lifestyle advice

I agree.  We don't use "PerWebRequest" for anything.  Just transient or
singelton.  We also just use auto factories in the cases where we need to
get access to a stateful object that needs dependencies auto resolved.  It
took a bit of getting used to using the auto factories, since some bits of
them are a tiny bit annoying, but now we've had pretty good luck.

Kelly


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »