Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3783516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:14:11+00:00 2026-05-19T11:14:11+00:00

Edit Orignal Title: My transaction is closed by the time it gets to my

  • 0

Edit

Orignal Title: My transaction is closed by the time it gets to my Repo. What am I doing wrong?

I got a answer to my origanl questions(I forgot to open the transaction lol). Now I am wondering if my code is automatically closing the session or if I have to somehow tell it to do this.


Hi

I am using mvc 3.0, nhibernate, fluent nhibernate and ninject 2.0

Global.asax

// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            // Hook our DI stuff when application starts
            SetupDependencyInjection();


            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }


        public void SetupDependencyInjection()
        {         
            // Tell ASP.NET MVC 3 to use our Ninject DI Container
            DependencyResolver.SetResolver(new NinjectDependencyResolver(CreateKernel()));
        }

        protected IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
                              {
                                 new NhibernateModule(),
                                 new ServiceModule(),
                                 new RepoModule()
                              };

            return new StandardKernel(modules);
        }

    }

Session Factory

public class NhibernateSessionFactory
    {
        public ISessionFactory GetSessionFactory()
        {
            ISessionFactory fluentConfiguration = Fluently.Configure()
                                                  .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("test")))
                                                  .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyMaps>())
                                                  .BuildSessionFactory();

            return fluentConfiguration;
        }
    }

Session Factory Provider

 public class NhibernateSessionFactoryProvider : Provider<ISessionFactory>
    {   
        protected override ISessionFactory CreateInstance(IContext context)
        {
            var sessionFactory = new NhibernateSessionFactory();
            return sessionFactory.GetSessionFactory();
        }
    }

Nhibernate Module

 public class NhibernateModule : NinjectModule
    {
        public override void Load()
        {
            Bind<ISessionFactory>().ToProvider<NhibernateSessionFactoryProvider>().InSingletonScope();
            Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope();
        }
    }

Service Module

  public class ServiceModule : NinjectModule
    {
        public override void Load()
        {
            Bind<ITest>().To<Test>();
        }
    }

Repo Module

 public class RepoModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IStudentRepo>().To<StudentRepo>();
        }
    }

HomeController

 private readonly ITest test;
        public HomeController(ITest test)
        {
            this.test = test;
        }

        //
        // GET: /Home/
        public ActionResult Index()
        {
           return View();
        }

Test(my service layer file)

  public class Test : ITest
    {
        private readonly IStudentRepo studentRepo;

        public Test(IStudentRepo studentRepo)
        {
            this.studentRepo = studentRepo;
        }

    }

Repo

  public class StudentRepo : IStudentRepo
    {
        private readonly ISession session;

        public StudentRepo(ISession session)
        {
            this.session = session;
        }
    }

When I look through my debugger at the session that is coming into my repo. It says the session is open and connected but the (session.Transaction).IsActive = false

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:14:11+00:00Added an answer on May 19, 2026 at 11:14 am

    You’re currently set up to use implicit transactions, which I don’t believe are exposed through session.Transaction. Of course, Use of implicit transactions is discouraged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[community edit: original title was python conditionals, OP is asking what is wrong with
Edit: original title convert numpy array to cvmat was a mistake - OpenCV's less
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
EDIT: Original Title: Question about the benefit of using an ORM. I want to
Edit: My original title has been sort of changed. I suspect the current title
I need the 100% .NET library to edit PDF Info like Author, Title, Creator,
EDIT: This question title originally was: How does Doctrine know last inserted id in
EDIT: Original title: When I add a custom control based on a timer, my
[EDIT] original title of this question was Getting the last element of a Postgres

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.