<commit_before>using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using log4net.Config;
using Rhino.ServiceBus.Actions;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Msmq;

namespace Rhino.ServiceBus.Hosting
{
    public class DefaultHost : MarshalByRefObject, IApplicationHost
    {
        private readonly ILog logger = LogManager.GetLogger(typeof(DefaultHost));
        private string assebmlyName;
        private AbstractBootStrapper bootStrapper;
        private IWindsorContainer container;
        private IStartableServiceBus serviceBus;
        private string bootStrapperName;

        public void SetBootStrapperTypeName(string typeName)
        {
            bootStrapperName = typeName;
        }

        public void Start<TBootStrapper>()
            where TBootStrapper : AbstractBootStrapper
        {
            SetBootStrapperTypeName(typeof(TBootStrapper).FullName);
            Start(typeof(TBootStrapper).Assembly.FullName);
        }

        public void Start(string asmName)
        {
            InitailizeBus(asmName);

            serviceBus.Start();

            bootStrapper.AfterStart();
        }

        private void InitailizeBus(string asmName)
        {
            string logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");

            XmlConfigurator.ConfigureAndWatch(new FileInfo(logfile));

            assebmlyName = asmName;

            CreateBootStrapper();

            log4net.GlobalContext.Properties["BusName"] = bootStrapper.GetType().Namespace;

            CreateContainer();

            InitializeContainer();

            bootStrapper.BeforeStart();

            logger.Debug("Starting bus");
            serviceBus = container.Resolve<IStartableServiceBus>();
        }

        private void InitializeContainer()
        {
            bootStrapper.InitializeContainer(container);
        }


        private void CreateContainer()
        {
            container = new WindsorContainer(new XmlInterpreter());
            var facility = new RhinoServiceBusFacility();
            bootStrapper.ConfigureBusFacility(facility);
            container.Kernel.AddFacility("rhino.esb", facility);
        }


        private void CreateBootStrapper()
        {
            logger.DebugFormat("Loading {0}", assebmlyName);
            var assembly = Assembly.Load(assebmlyName);

            Type bootStrapperType = null;

            if (string.IsNullOrEmpty(bootStrapperName) == false)
                bootStrapperType = assembly.GetType(bootStrapperName);

            bootStrapperType = bootStrapperType ??
                GetAutoBootStrapperType(assembly);
            try
            {
                bootStrapper = (AbstractBootStrapper)Activator.CreateInstance(bootStrapperType);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Failed to create " + bootStrapperType + ".", e);
            }

        }

        public IWindsorContainer Container
        {
            get { return container; }
        }

        private static Type GetAutoBootStrapperType(Assembly assembly)
        {
            var bootStrappers = assembly.GetTypes()
                .Where(x => typeof(AbstractBootStrapper).IsAssignableFrom(x))
                .ToArray();

            if (bootStrappers.Length == 0)
                throw new InvalidOperationException("Could not find a boot strapper for " + assembly);

            if (bootStrappers.Length > 1)
            {

                throw new InvalidOperationException("Found more than one boot strapper for " + assembly +
                    " you need to specify which boot strapper to use: " + Environment.NewLine +
                    string.Join(Environment.NewLine, bootStrappers.Select(x => x.FullName).ToArray()));
            }

            return bootStrappers[0];
        }

        public void Dispose()
        {
            if (bootStrapper != null)
                bootStrapper.Dispose();
            if (serviceBus != null)
                serviceBus.Dispose();
            if (container != null)
                container.Dispose();
        }

        public override object InitializeLifetimeService()
        {
            return null; //singleton
        }

        public void InitialDeployment(string asmName, string user)
        {
            InitailizeBus(asmName);

            foreach (var action in container.ResolveAll<IDeploymentAction>())
            {
                action.Execute(user);
            }

            foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
            {
                action.Execute();
            }
        }
    }<commit_msg>Applying slightly modified patch from <NAME>, adding a way to pass the container and configuration for the container to the default host.<commit_after>using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using log4net.Config;
using Rhino.ServiceBus.Actions;
using Rhino.ServiceBus.Impl;

namespace Rhino.ServiceBus.Hosting
{
    public class DefaultHost : MarshalByRefObject, IApplicationHost
    {
        private readonly ILog logger = LogManager.GetLogger(typeof(DefaultHost));
        private string assebmlyName;
        private AbstractBootStrapper bootStrapper;
        private IWindsorContainer container;
        private IStartableServiceBus serviceBus;
        private string bootStrapperName;
    	private string standaloneCastleConfigurationFileName;

        public void SetBootStrapperTypeName(string typeName)
        {
            bootStrapperName = typeName;
        }

        public void Start<TBootStrapper>()
            where TBootStrapper : AbstractBootStrapper
        {
            SetBootStrapperTypeName(typeof(TBootStrapper).FullName);
            Start(typeof(TBootStrapper).Assembly.FullName);
        }

        public void Start(string asmName)
        {
            InitailizeBus(asmName);

            serviceBus.Start();

            bootStrapper.AfterStart();
        }

        private void InitailizeBus(string asmName)
        {
            string logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");

            XmlConfigurator.ConfigureAndWatch(new FileInfo(logfile));

            assebmlyName = asmName;

            CreateBootStrapper();

            log4net.GlobalContext.Properties["BusName"] = bootStrapper.GetType().Namespace;

            CreateContainer();

            InitializeContainer();

            bootStrapper.BeforeStart();

            logger.Debug("Starting bus");
            serviceBus = container.Resolve<IStartableServiceBus>();
        }

        private void InitializeContainer()
        {
            bootStrapper.InitializeContainer(container);
        }


        private void CreateContainer()
        {
			if (container == null)
			{
				container = string.IsNullOrEmpty(standaloneCastleConfigurationFileName) 
					? new WindsorContainer(new XmlInterpreter()) 
					: new WindsorContainer(new XmlInterpreter(standaloneCastleConfigurationFileName));
			}
        	var facility = new RhinoServiceBusFacility();
            bootStrapper.ConfigureBusFacility(facility);
            container.Kernel.AddFacility("rhino.esb", facility);
        }


        private void CreateBootStrapper()
        {
            logger.DebugFormat("Loading {0}", assebmlyName);
            var assembly = Assembly.Load(assebmlyName);

            Type bootStrapperType = null;

            if (string.IsNullOrEmpty(bootStrapperName) == false)
                bootStrapperType = assembly.GetType(bootStrapperName);

            bootStrapperType = bootStrapperType ??
                GetAutoBootStrapperType(assembly);
            try
            {
                bootStrapper = (AbstractBootStrapper)Activator.CreateInstance(bootStrapperType);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Failed to create " + bootStrapperType + ".", e);
            }

        }

        public IWindsorContainer Container
        {
            get { return container; }
        }

        private static Type GetAutoBootStrapperType(Assembly assembly)
        {
            var bootStrappers = assembly.GetTypes()
                .Where(x => typeof(AbstractBootStrapper).IsAssignableFrom(x))
                .ToArray();

            if (bootStrappers.Length == 0)
                throw new InvalidOperationException("Could not find a boot strapper for " + assembly);

            if (bootStrappers.Length > 1)
            {

                throw new InvalidOperationException("Found more than one boot strapper for " + assembly +
                    " you need to specify which boot strapper to use: " + Environment.NewLine +
                    string.Join(Environment.NewLine, bootStrappers.Select(x => x.FullName).ToArray()));
            }

            return bootStrappers[0];
        }

        public void Dispose()
        {
            if (bootStrapper != null)
                bootStrapper.Dispose();
            if (serviceBus != null)
                serviceBus.Dispose();
            if (container != null)
                container.Dispose();
        }

        public override object InitializeLifetimeService()
        {
            return null; //singleton
        }

        public void InitialDeployment(string asmName, string user)
        {
            InitailizeBus(asmName);

            foreach (var action in container.ResolveAll<IDeploymentAction>())
            {
                action.Execute(user);
            }

            foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
            {
                action.Execute();
            }
        }

		public void UseContainer(IWindsorContainer theContainer)
		{
			this.container = theContainer;
		}

		public void UseStandaloneCastleConfigurationFileName(string configurationFileName)
		{
			this.standaloneCastleConfigurationFileName = configurationFileName;
		}
    }
{'fraction_non_alphanumeric': 0.07903413498836308, 'fraction_numerical': 0.0015515903801396431, 'mean_word_length': 2.0766706443914082, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578632', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2490, 'n_words': 529}