You can move any initialization outside your application, even better... you should move it. You can easily inject the injector.
in web you can use HttpModule... why ? WCF has "behaviors" configurable via XML... why ? MVC has "ActionFilters" and "ControllerFactory".... why ? Somebody are pushing you to do the wrong thing ? arg!! such bad guys!! With the argument "you app. can't work without NH" I saw NH calls in the code behind, if that is good for you... well... good luck!! On Mon, Jun 28, 2010 at 2:48 PM, Vadim Chekan <[email protected]> wrote: > I agree with Felipe, > > 1. By moving persistence initialization into a separate http module > nothing changes: you are still having persistence calls in > presentation tier: HttpModule is part of presentation framework. May > be you imply the fact that it allows you to remove NH from referenced > assemblies? Then it does not remove dependency but creates an illusion > of dependency being removed because your app won't even start without > NH assembly. > > 2. Often system components require initialization. In this case Global > acts not as part of presentation tier, but as application start hook, > where you put your init calls. For example in console application > it'll be Main(), in Win Service it'll be OnStart. Moving init calls > into HttpModule, which were not directly intended for initialization > make program more difficult to read. > > 3. I can think of legitimate reasons for removing binary dependency, > for example application can use one of several persistence strategies. > Then as architect you may feel bad about linking libraries which may > be not used at all. > In scenarios when NH is the only option, linking HN assembly is a good > thing. And putting init call where it is expected to be is good too. > > Vadim. > > On Jun 26, 2:53 pm, nadav s <[email protected]> wrote: > > no, its a matter of having a direct reference to the DAL or event worse, > a > > persistance tool that your dal uses, from the presentation layer. its a > > basic 3 tier anti pattern. > > > > On Sun, Jun 27, 2010 at 12:22 AM, Felipe Oriani <[email protected]> > wrote: > > > Hi guys ... thanks for the awsers! > > > > > What is there any difference between I use an HttpModule or Global.asax > > > (prerequest / postrequest) events ? one has more performace than the > > > other? > > > > > On Sat, Jun 26, 2010 at 3:56 PM, John Davidson <[email protected] > >wrote: > > > > >> Unfortunately there are _many_ samples on the Internet that show > almost > > >> the same initialization using the global.asax This use of an > HttpModule for > > >> this purpose needs to be described as a best practice for initializing > a > > >> session in NHibernate. > > > > >> John Davidson > > > > >> Sent from my iPad > > > > >> On 2010-06-26, at 11:55, nadav s <[email protected]> wrote: > > > > >> it has nothing to do with you're question, but i don't think its wise > > >> putting this code in the global asax, and therefor making you're > > >> presentation layer too much aware of you're persistancy. > > >> you can write an HttpModule that does just that and register it in the > web > > >> config. > > > > >> On Sat, Jun 26, 2010 at 6:18 PM, Felipe Oriani < <[email protected]> > > >> [email protected]> wrote: > > > > >>> Hi all, I'm developing an application using Asp.Net MVC. I've > developed > > >>> a session per Request... so when the browser request something from > server, > > >>> the app start an session. > > > > >>> By the way, I have a page in my website that each second does a > > >>> asynchronous request by Json to take some information at cache (and > the > > >>> first time, the cache is loaded from database, by repositories using > > >>> Nhibernate). Everything is fine, but when I see the application > running with > > >>> NHProf, I see all "ISession" per request ... but any command is > executed > > >>> (because I load a cache). > > > > >>> I wonder, if doing so may cause a problem in the future? Or, with > many > > >>> accesses the web application may become slow ? > > > > >>> At my global.asax I do this: > > > > >>> public override void Init() > > >>> { > > >>> base.Init(); > > > > >>> PreRequestHandlerExecute += OpenNHibernateSession; > > >>> PostRequestHandlerExecute += DisposeNHibernateSession; > > >>> } > > > > >>> private static void OpenNHibernateSession(object sender, > > >>> EventArgs e) > > >>> { > > >>> if (RequestHelper.IsStaticFiles()) // || > > >>> RequestHelper.IsJson()) = to avoid calls Json if necessary, but i'll > need > > >>> use h in some called jsons > > >>> return; > > > > >>> ManagedWebSessionContext.Bind(HttpContext.Current, > > >>> _sessionFactory.OpenSession()); > > >>> } > > > > >>> private static void DisposeNHibernateSession(object sender, > > >>> EventArgs e) > > >>> { > > >>> if (RequestHelper.IsStaticFiles()) // || > > >>> RequestHelper.IsJson()) > > >>> return; > > > > >>> var session = > > >>> ManagedWebSessionContext.Unbind(HttpContext.Current, > _sessionFactory); > > >>> if (session != null) > > >>> session.Dispose(); > > > > >>> } > > > > >>> If someone can help-me... I'll! appreciate > > > > >>> PS: Sorry for my english! > > > > >>> Cheers > > > > >>> -- > > >>> ______________________________________ > > >>> Felipe B. Oriani > > >>> <[email protected]>[email protected] | > > >>> <http://www.felipeoriani.com.br>www.felipeoriani.com.br > > > > >>> "...Trabalhe quanto puder, tornando-se útil quanto possível..." , por > > >>> André Luiz > > > > >>> -- > > >>> You received this message because you are subscribed to the Google > Groups > > >>> "nhusers" group. > > >>> To post to this group, send email to <[email protected]> > > >>> [email protected]. > > >>> To unsubscribe from this group, send email to > > >>> <nhusers%[email protected]<nhusers%[email protected]> > > > > >>> [email protected]<nhusers%[email protected]> > . > > >>> For more options, visit this group at > > >>> <http://groups.google.com/group/nhusers?hl=en> > > >>>http://groups.google.com/group/nhusers?hl=en. > > > > >> -- > > >> 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]<nhusers%[email protected]> > . > > >> For more options, visit this group at > > >>http://groups.google.com/group/nhusers?hl=en. > > > > >> -- > > >> 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]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > > > > >> . > > >> For more options, visit this group at > > >>http://groups.google.com/group/nhusers?hl=en. > > > > > -- > > > ______________________________________ > > > Felipe B. Oriani > > > [email protected] |www.felipeoriani.com.br > > > > > "...Trabalhe quanto puder, tornando-se útil quanto possível..." , por > André > > > Luiz > > > > > -- > > > 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]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/nhusers?hl=en. > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- 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.
