Search code examples
asp.net-mvcnhibernatefluent-nhibernateseparation-of-concerns

Is the ASP.NET MVC web layer supposed to reference the nHibernate .dlls?


In all of the talk about separation of concerns, I seem to keep running into the problem of my ASP.NET MVC application having to reference a lot of libraries related to nhibernate and fluent nhibernate for my dependency injection.

Is this typical? Is there a different way I am supposed to be solving this? I try to put all of the logic involving nHibernate into a Data project, but when I have to wire up ISessionFactory and ISession, I have to have access to these in my Web Layer. Has anyone found a workaround to this?


Solution

  • Honestly it's not a big thing to worry about. I know you would like to keep all data related dependencies out of your UI layer but if you want to use NHibernate correctly where you have an ISession per request then you have to set it up in your Application_Start of the global.asax. Granted you probably could wrap everything in your own interface and hide any dependency to NHibernate but it's really overkill. Don't try to hide what you're using, how often are you going to switch your ORM?