0

I am currently working on a solution in visual studio which I am going to deploy on windows azure. The solution consists of a MVC3 web role where data from SQL Server is represented. I've already set up Ninject and Fluent NHibernate to decouple the views from the database and the concrete implementations.

What I'd like to do now, is to put all the data access logic (i.e. NHibernate along with the repositories for data access) into a separate c# project so that I can reuse this project for the MVC3 project AND a future SOA project.

Any ideas how I may achieve this? I figured out how to do it with "code-only" classes, but a handful issues come up when using hibernate. I guess it's related to the ISession object in the global.asx which is created for each web request.

Any hints to simple implementations, scenarios or how-to's would be very helpful. If needed I can post code as well - just let me know which parts in detail ;-)

Regards, Martin

Martin Horvath
  • 466
  • 1
  • 6
  • 18
  • 1
    as I did many other times, I suggest a layered approach where only the DAL knows about the underlying ORM and database techniques. Check my answer here: http://stackoverflow.com/a/7474357/559144 if you want to use NHibernate it stays basically the same except replacing EF with NH and if you need to handle Session you can have a service layer which encapsulates the logic and servers to the MVC and SOA projects entry points to the Business Logic. – Davide Piras Feb 13 '12 at 20:14

1 Answers1

0

If I understand correctly, I don't see a problem implementing a Service class library that gets requests from either the UI or the SOA layer and executes them. for example-

public class UsersService
        {
            private ISession _Session;

            // Session is injected 
            public UsersService(ISession session)
            {
                _Session = session;
            }

            public IEnumerable<User> GetAllUsers()
            {
                return _Session.QueryOver<User>().List();
            }
        }
J. Ed
  • 6,692
  • 4
  • 39
  • 55