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

  • Home
  • SEARCH
  • 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 5985387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:31:23+00:00 2026-05-22T22:31:23+00:00

My WinForm application is configured like this: public class RepositoriesInstaller : IWindsorInstaller { public

  • 0

My WinForm application is configured like this:

 public class RepositoriesInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(AllTypes.FromAssemblyContaining<EventRepository>()
          .BasedOn(typeof(IRepository<>))
          .WithService.AllInterfaces()
          .Configure(c => c.LifeStyle.Transient));
    }
}

Program.cs

   FrmStart form1 = CastleContainer.Resolve<FrmStart>();

I inject Repository class in my forms but I have to be sure that NHibernate session will be closed when I will close the form.
Is this the right path to dispose it?

   public class EventRepository : IRepository<Event>,IDisposable
{
    private readonly ISession session;

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

    public void Dispose()
    {
        session.Close();
    }

update

Is this code valid?

 private void button1_Click(object sender, EventArgs e)
    {
        FrmStart form1 = CastleContainer.Resolve<FrmStart>();
        form1.FormClosed += new FormClosedEventHandler(form1_FormClosed);
        form1.Show();

    }
    void form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        CastleContainer.Instance.Release(sender);
    }
  • 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-22T22:31:23+00:00Added an answer on May 22, 2026 at 10:31 pm

    assuming from you example you have a main frm(frmMain) and and additional one(frm1) you’d like to show on some button click
    You have to put all of them into the container of course among their dependencies, than UI root = frmMain contructor will look like

    public partial class frmMain : Form
    {
        frm1 _frm1Instance
        public frmMain(frm1 frm1Instance)
        {
          _frm1Instance = frm1Instance;
          //...
        }
    
            private void button1_Click(object sender, EventArgs e)
            {
                _fmr1Instance.Show();
    
            }
    }
    

    on the Guywire among Wire and DeWire methods as per example, you’ll have a method like

    public System.Windows.Forms.Form GetRoot()
    {
        return container.Resolve<frmMain>();
    }
    

    than into you main method, you’ll create an instance of Guywire and you’ll use Form returned by GetRoot() to start your app

    If you decide to follow this way, you cannot dispose your frm1 on close otherwise on next button1 click you’ll attempt to access a diposed object.

    If you really need to dipose frm1, I suggest you to inject a TypedFactory(WindsorFacility) instead of frm1 instance, get an instance through the factory and dipose it through the factory as well.
    see: http://mookid.dk/oncode/archives/1854

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

Sidebar

Related Questions

In Winform application I have a class with 2 properties and I want the
This is a .NET winform application question. I come to this design from time
I have a winform application and this winform application has created few files. I
My winform application crashes as soon as its been launched. This problem is only
Assume in a winform application we have in program.cs : static class Program {
I am running code coverage using VS 2010. This is a winform application. In
I have a C# WinForm application. This program is designed to create and open
This is a WinForm application question in .net. It is about MDI form. I
My winform application is launched by another application (the parent), I need determine the
In winform application, how do I give a different (different from the blue one)

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.