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 7067983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:16:05+00:00 2026-05-28T05:16:05+00:00

I’m learning NHibernate and have created some unit tests and it’s going quite well.

  • 0

I’m learning NHibernate and have created some unit tests and it’s going quite well. My main app only has two layers:

  1. Presentation (WPF app)
  2. Domain (has business logic and data access)

and of course I have my Unit test project (Test).

My unit tests call my SessionManager class to build a SessionFactory during [TestFixtureSetup]. Each [Test] then gets a Session to perform the data access unit test. I’m wondering how I should do this in my WPF project.

I have created a simple dialog box to see if I can wire up my WPF app to my database. It feels wrong to have a reference to NHibernate in my Presentation layer, am I right in this feeling? If so, how should I get a session to store an object when a user clicks Add on my form to store something? Here’s some of my code:

public class SessionManager
{
    private ISessionFactory _sessionFactory;

    public SessionManager()
    {
        _sessionFactory = GetSessionFactory();
    }

    public ISession GetSession()
    {
        return _sessionFactory.OpenSession();
    }

    private ISessionFactory GetSessionFactory()
    {
        return (new Configuration()).Configure().BuildSessionFactory();
    }
}

In my Test project I have this kind of thing:

    [TestFixtureSetUp]
    public void TestFixtureSetup()
    {
        log4net.Config.XmlConfigurator.Configure();
        DatabaseFixtureSetUp();
        _sessionManager = new SessionManager();
    }

    [SetUp]
    public void Setup()
    {
        DatabaseSetUp();

        _session = _sessionManager.GetSession();
    }

I’m not sure how to structure my Presentation layer code to store an object. I have this on my form:

    private void btnAddBroker_Click(object sender, RoutedEventArgs e)
    {
        var broker = new Broker
        {
            Name = txtBrokerName.Text,
            IsActive = (bool)chkIsActive.IsChecked,
            IsDefault = (bool)chkIsDefault.IsChecked
        };

        // save the broker object to the database
        // is it ok to have NHibernate code here? feels wrong

    }

How would you do it?

  • 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-28T05:16:06+00:00Added an answer on May 28, 2026 at 5:16 am

    Although I’m not an expert in WPF applications, coming from Web Development, I would say yes It does feel wrong for the presentation layer to be generating a session.

    My recommendation would be to create a Factory class (Which I see you did with SessionManager) that is responsible for creating a NHibernate Session. Your business layer could then call the factory class to get a NHibernate Session, then use it in your business layer to process whatever request that needs to be fulfilled.

    You could then even inject that factory class and business layer using and Dependency Injection, if you are sticking to IOC principles.

    I’m sure you already know this, but I’ll mention it anyway:
    However you decide to split things up, the goal is to keep user interface manipulation code in one layer and business code in another, so that if you should need to port this application to, say a Web application, the business layer could be re-used and only the presentation layer would need to be developed.

    Seeing that you are already doing unit testing, writing your unit tests first will force you naturally into thinking about splitting up responsibilities of classes in such a way that they are unit testable, and that is a very good thing. I believe you are on the right path.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.