Free NHibernate Template for IHttpModule and Console Applications

I currently have a C # MVC 2 web application using Fluent NHibernate (+ LINQ) in the repository template, and I use Ninject to handle the MVC controller constructor request for it to be passed to the repository.

My current NHibernate code is currently connected to the IHttpModule module, so the session can be opened and closed using a web request.

This works fine until I try to connect my domain model to a console application.

First, I decided to move the database logic to my domain model. I suppose this is bad behavior, but I am asking for help in developing the code here, so please feel free to make suggestions. I wanted to do this because I want to write a console application + web application for this domain model without worrying about where and how the data is stored. Perhaps I should have a separate Infrastructure project that uses a domain model to perform a specific implementation?

Returning to the question ... I ran into a problem when it seems that Fluent NHibernate GetCurrentSession () assumes that you are using the Internet - it crashes and I get a trace of some NH code mentioning WebSession.

For reference, the code is here: https://github.com/cthielen/RightsManagement .

, ; , FNH + Linq , Web, - , ( NH) .

+3
2

. , , . , TDD? ? IoC? .

, , - , . , ISession , , , , HTTP. .

public class PeopleRepository {
    public PeopleRepository(ISession session) {
        // store session
    }
}

IoC . , -, .

, NHibernate . , .

. .

+1

, , - ( Unit Of Work, )

using (var session = SessionFactory.Create())
{
   // do all work here
}

, , (, ).

factory SessionCreated SessionDestroyed, , nhibernate factory.

-

+1

All Articles