Sanity check on unique per request

155 views
Skip to first unread message

Mikael Henriksson

unread,
Jan 13, 2010, 6:44:12 AM1/13/10
to structure...@googlegroups.com
Hey, I just wanted to confirm that this is the intended usage in the new API. It feels almost to easy:


For<IUnitOfWork>()
    .LifecycleIs(new UniquePerRequestLifecycle())
    .Use(x => new UnitOfWork(x.GetInstance<ISessionFactory>(Keys.SessionFactoryName)));

Andreas Öhlund

unread,
Jan 13, 2010, 7:33:02 AM1/13/10
to structure...@googlegroups.com
This will give you an unique UoW every time you try to resolve IUnitOfWork. This is probably not correct if you are using this in a web app (UoW per request == HttpContext or Hybrid)

The mapping between scopes and lifecycles are as follows:

case InstanceScope.PerRequest:
                    return null;

                case InstanceScope.Singleton:
                    return new SingletonLifecycle();

                case InstanceScope.HttpContext:
                    return new HttpContextLifecycle();

                case InstanceScope.ThreadLocal:
                    return new ThreadLocalStorageLifecycle();

                case InstanceScope.Hybrid:
                    return new HybridLifecycle();

                case InstanceScope.HttpSession:
                    return new HttpSessionLifecycle();

                case InstanceScope.HybridHttpSession:
                    return new HybridSessionLifecycle();

                case InstanceScope.Unique:
                    return new UniquePerRequestLifecycle();

Hope this helps!
/Andreas

http://andreasohlund.blogspot.com
http://twitter.com/andreasohlund





From: mik...@zoolutions.se
Date: Wed, 13 Jan 2010 12:44:12 +0100
Subject: [sm-users] Sanity check on unique per request
To: structure...@googlegroups.com


Keep your friends updated— even when you’re not signed in.

Mikael Henriksson

unread,
Jan 13, 2010, 10:29:03 AM1/13/10
to structure...@googlegroups.com
In this case it was actually intended. Thanks :)

--
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.


Reply all
Reply to author
Forward
0 new messages