I was wondering if someone can suggest the best pattern to use in the above scenario, assuming that
A) StructureMap is used in the following way:
cfg.For<ISession>()
.LifecycleIs(new TransientLifecycle())
.Use(ctx => ctx.GetInstance<ISessionFactory>().OpenSession());
B) I would like all method calls to various services/repositories within a single controller action wrapped inside a TransactionScope, meaning if any of the actions goes wrong, then none of them should be committed.
I read somewhere that the session must be constructed within the TransactionScope block if this were to work which in my case is not so given that session is injected within each repository by Structuremap.
If you want more control over the scope of your ISession I would inject an ISessionFactory instead in your controllers and leave the ISession being injected in your repositories or inject a factory/factories to create your repository instance(s). This way in each controller action you could do something like: