Thanks Jason for your post regarding transaction. I am going to use this later since I would like to have IoC all over my application.
THANKS ONCE AGAIN Best Regards Sheri On 29 Jan, 15:30, Jason Meckley <[email protected]> wrote: > good to know you solved the problem! > > I would make 1 tiny change to the transaction code (assuming you can > resolve the session from the container directly.) > using (var tx = WindsorContainerAccessorUtil > .ObtainContainer() > .Resolve<ISession>() > .BeginTransaction()) > { > try > { > ... > tx.Commit(); > } > catch > { > tx.Rollback(); > throw; > } > > } > > Another approach to managing the session would be implementing an > Interceptor (similar to filters) IInterceptor is part of Castle and > can be applied to any component (not a sealed class and virtual > members) registered in the container. with this you could do something > like > class TransactionInterceptor:IInterceptor > { > private ISession session; > public TransactionInterceptor(ISession session) > { > this.session = session; > } > > public void Intercept(IInvocation invocation) > { > if(session.Transaction.IsActive) > { > invocation.Proceed(); > return; > } > > using(var tx = session .BeginTransaction()) > { > try > { > invocation.Proceed(); > tx.Commit(); > } > catch > { > tx.Rollback(); > throw; > } > } > } > > } > > there is the issue that interceptors will intercept all calls to > public/protected virtual memebers and you may not want a transaction > on every one. For that you can Implement IOnBehalfOf (or IAwareOf, I > forget exactly) which allows you to selectively choose when the > invocation is intercepted. I'm not 100% sure how to use/configure it. > The only implementation I have seen was on a blog post by Ayende way > back in the day dealing with query caching and generic repositories. > > On Jan 29, 5:21 am, Sheri <[email protected]> wrote: > > > > > Thanks Jason > > > I have had an overridden controller factory almost like yours here. It > > is solved now. > > > The only thing that I do not use is Filter for managing transaction. > > The reason is I use ASP .NET MVC Controller which I cannot use Filter > > in Monorail (due to confliction). > > > Due to lack of time I am satisfied to use: > > > using (ITransaction tx = WindsorContainerAccessorUtil.ObtainContainer > > ().Resolve<ISessionFactory>().GetCurrentSession().BeginTransaction()) > > { > > ... > > > } > > > Thanks once again > > /Sheri > > > On Jan 29, 3:03 am, Jason Meckley <[email protected]> wrote: > > > > I don't have anything concrete handy, but here is the concept. > > > MVC has an interface, well call it IControllerFactory. that has a > > > single method. > > > interface IControllerFactory > > > { > > > IController CreateController(Uri uri)} > > > > the framework comes with a default implementation. we'll call it > > > class DefaultControllerFactory : IControllerFactory > > > { > > > public IController CreateController(Uri uri) > > > { > > > ... > > > }} > > > > you can ovrride this by creating your own implementation > > > class WindsorControllerFactory : IControllerFactory > > > { > > > IKernel kernel; > > > WindsorControllerFactory(IKernel kernel) > > > { > > > this.kernel = kernel; > > > } > > > public IController CreateController(Uri uri) > > > { > > > var key = parse IContoller key from uri. > > > return kernel.Resolve<IController>(key); > > > }} > > > > Now that we have this new implementation of the controller factory we > > > need to tell MVC to use this one instead of the default. > > > class Global: HttpApplication > > > { > > > private static IWindsorContainer container; > > > public void Application_Start(object sender, EventArgs e) > > > { > > > container = new WindsorContainer > > > ().AddComponent<WindsorControllerFactory>(); > > > SomeMvcConfigurationObject.ControllerFactoryToUse = > > > container.Resolve<WindsorControllerFactory>(); > > > }} > > > > and now your controllers are resolved from your factory instead of the > > > default. MvcContrib (http://www.codeplex.com/MVCContrib) does most of > > > this work for you. if you reference mvccontrib in your project you can > > > use this to enhance the default MVC features. > > > > "How long does it take to be a capable developer like you?! " > > > I have been a developer for ~9 years. I didn't have a clue what i was > > > doing for the first 5. the turning point for me was *nothin' but .net* > > > (http://www.jpboodhoo.com/training.oo). Up until then I had no idea > > > what OOP really was. after than projects like Castle and Nhibernate > > > made more sense and i could understand what was happening when I > > > looked at the code.www.ayende.com,www.codebetter.comandwww.lostechies.com > > > also helped me progress. > > > > On Jan 28, 4:24 pm, Sheri <[email protected]> wrote: > > > > > Hi Jason > > > > Thanks again > > > > I really appreciate all your help. > > > > I have solved my problem but it is not the real one! maybe I need > > > > more knowledge to understand your comments. > > > > Your comments are advance comment so I need read them more than once > > > > to understand. (typically junior developer!) > > > > > If you have some example for your description below I am very thankful > > > > otherwise I am still very thankful for all that time you spent to help > > > > me. > > > > > Best Regards > > > > Sheri > > > > P.S. How long does it take to be a capable developer like you?! > > > > > On 28 Jan, 15:25, Jason Meckley <[email protected]> wrote: > > > > > > Ah, ok. I'm not familar with OoTB, but the MS MVC default ctor issue I > > > > > do know about. The default controller resolution method for MS MVC is > > > > > using a default constructor. But you can override this by implementing > > > > > your own ControllerFactory. There may also be other factory interfaces > > > > > you can replace to resolve Filters, membership, etc. If so you would > > > > > want to override these as well. where the the Factory implementation > > > > > would resolve the objects from the kernel. > > > > > > I use Monorail which ties in very nicely with Windsor, so i take for > > > > > granted that Filters/Controller/etc are resolved from the Kernel. > > > > > There is a project called MvcContrib which is primarly maintained by > > > > > HeadSpring. If you are not familar with this project I would highly > > > > > recommend it. It picks up with MS MVC stops. > > > > > > If there isn't a way to change how the membership provider is created. > > > > > you will need to find a hook to inject the dependencies via > > > > > properties. it would look something like > > > > > > var provider = GetProviderByDefaultCtor. > > > > > provider.Dependency = kernel.Resolve<Dependency>(); > > > > > //then return or use the provider. > > > > > > Not as clean, but it gets the dependencies into the provider. > > > > > > On Jan 28, 7:48 am, Sheri <[email protected]> wrote: > > > > > > > Hope I do not make you angry with my daily questions!! > > > > > > > I have followed all advices. Everything works fine and SessionScope > > > > > > seems to be worked fine. but I still have "Session Closed!" error. I > > > > > > get this error exactly when the logined page will appear after > > > > > > login! > > > > > > > The reason that I got through debug is "Membership Provider". this > > > > > > OoTB approach need default constructor, and DI needs another > > > > > > constructor for DI objects, the problem begins here. Membership > > > > > > Provider initialized (default ctor) by ASP .NET MVC oOTB membership > > > > > > approach and when the user will log in Membership provider > > > > > > initializes > > > > > > via DI (ctor with DI objects) again that I guess the older session > > > > > > is > > > > > > no more active. > > > > > > > tired of these conflicts and lack of my knowledge to solve it :-S > > > > > > > Any idea? > > > > > > > Thanks once again and again > > > > > > /Sheri > > > > > > > On 27 Jan, 16:20, Jason Meckley <[email protected]> wrote: > > > > > > > > you lost me :) i think I get it, but want to be sure. > > > > > > > 1. you are subclassing asp.net MembershipProvider > > > > > > > 2. your implementation utilizes ISession > > > > > > > 3. your implementation isn't registered in the container and > > > > > > > therefore > > > > > > > cannot be resolved automatically > > > > > > > > I haven't used the MembershipProvider explicitly. The apps I > > > > > > > create > > > > > > > are intranet apps on a Windows Domain. We utlize windows > > > > > > > authentication, so I'm haven't had to explicitly control the login > > > > > > > process. > > > > > > > > can you post the relevant code for the provider (and associated > > > > > > > objects)? We should be able to get this to work. > > > > > > > > On Jan 27, 9:00 am, Sheri <[email protected]> wrote: > > > > > > > > > Jason, thanks again for your quick answer! > > > > > > > > > All of component who injects session are transient. > > > > > > > > The only thing that I can guess is "MembershipProvider" in ASP > > > > > > > > .NET > > > > > > > > MVC. I cannot register it as a component. and since I user one > > > > > > > > of my > > > > > > > > services in my costumized provider I should register this one > > > > > > > > as a > > > > > > > > transient component too but I cannot do. > > > > > > > > > Is it true? what can I use instead of OoTB "Membership > > > > > > > > Provider" in > > > > > > > > ASP .NET MVC 1.0? > > > > > > > > > /Sheri > > > > > > > > > On 26 Jan, 22:32, Jason Meckley <[email protected]> > > > > > > > > wrote:> if you are injecting the session into a service, the > > > > > > > > service must be > > > > > > > > > Transient, also with objects that utilize these service must > > > > > > > > > be > > > > > > > > > transient. here are some examples > > > > > > > > > > controller > dao > session. all must be transient > > > > > > > > > controller > service > > > > > > > > > > dao > session. controller and dao must be > > > > > > > > > transient, > > > > > > > > > service can be a singleton, if necessary. > > > > > > > > > > by default component lifestyles are "undefined" > > ... > > läs mer » -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
