R – NHibernate Session and Repository

nhibernate

I am writing some unit test and I have a unit testing base class which opens the transaction and closes the transaction. The purpose of the transaction is to rollback the changes so the database is empty once the unit tests are finished running. The transaction is dependent on the ISession object.

Now, the problem is that my CustomerRepository needs to insert customer data into the database. How would CustomerRepository gets the hold of the ISession which has been opened by BaseTest class?

I can pass the ISession to the repository in the constructor but that looks ugly? any suggestions?

Best Answer

IMHO passing the ISession in the repository's constructor is the right thing to do. That's what dependency injection is about...

Related Topic