How to inject HttpSessionStateBase into components

369 views
Skip to first unread message

CVertex

unread,
Aug 14, 2009, 6:02:43 AM8/14/09
to Autofac
Howdy,

As always, lovin Autofac... but sometimes I get a bit confused about
it's interaction with web mvc.


I have a component ShopCartController, which implement
IShopCartController and takes HttpSessionStateBase as a dep.

What's the best way to inject HttpSessionStateBase into a component
without accessing a singleton (like HttpContext.Current)?

Or, should I be registering HttpSessionStateBase myself?

Or, should I injecting HttpContextBase or some other ASP.NET
abstractions http class?

Any advise is greatly appreciated,
CV

CVertex

unread,
Aug 14, 2009, 6:10:39 AM8/14/09
to Autofac
I should add that while ShopCartController uses the httpsessionstate,
instances of shopcartcontroller are still container scoped
transients.

They are transients because of their dep on Db persistence, which i
prefer to clean up with every request.

The session state is only used for persistence.

It seems others have built containers that are session scoped. Would
this be a good idea for what I'm doing?

Matt Burton

unread,
Aug 14, 2009, 1:01:47 PM8/14/09
to aut...@googlegroups.com
How about abstracting away access to session state behind a service
and managing that as a separate component with it's own lifecycle?

CVertex

unread,
Aug 15, 2009, 1:07:44 AM8/15/09
to Autofac
Yeah, I should do this so that I can do other types of persistence
later.

On Aug 15, 3:01 am, Matt Burton <matt.bur...@gmail.com> wrote:
> How about abstracting away access to session state behind a service
> and managing that as a separate component with it's own lifecycle?
>
Reply all
Reply to author
Forward
0 new messages