public static void RefreshAllBundles(IBundleContext context)
        {
            // parse each folders to register new bundles
            foreach (var folderPath in Directory.GetDirectories(Path.GetFullPath(string.Format("Bundles"))))
            {
                var bundleName = new DirectoryInfo(folderPath).Name;
                var bundleInfo = context.GetBundle(bundleName);
                if (bundleInfo == null)
                {
                    string path = Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll", bundleName));

                    // the assembly doesn't exist, try the bundle.config? Web.config?
                    if (!File.Exists(path))
                    {
                        System.Configuration.Configuration configuration = null;

                        if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\{0}.dll.config", bundleName))))
                        {
                            configuration = ConfigurationManager.OpenExeConfiguration(path);
                        }
                        else if (File.Exists(Path.GetFullPath(string.Format("Bundles\\{0}\\web.config", bundleName))))
                        {
                            VirtualDirectoryMapping vdm =
                                new VirtualDirectoryMapping(
                                    Path.GetFullPath(string.Format("Bundles\\{0}", bundleName)), true);
                            WebConfigurationFileMap wcfm = new WebConfigurationFileMap();
                            wcfm.VirtualDirectories.Add("/", vdm);

                            // Get the Web application configuration object.
                            configuration = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
                        }
                        else
                        {
                            throw new BundleNotFoundException(bundleName, new Version());
                        }

                        // TODO : better error handling
                        var section = (BundleConfigurationSection) configuration.GetSection("bundleConfiguration");

                        path = Path.GetFullPath(string.Format("Bundles\\{0}\\{1}", bundleName, section.BundlePath));
                        if (!File.Exists(path))
                            throw new BundleNotFoundException(bundleName, new Version());
                    }

                    // create the bundle with all information needed
                    var assembly = Assembly.ReflectionOnlyLoadFrom(path);
                    var version = assembly.GetName().Version;
                    bundleInfo = new BundleInfo
                    {
                        Path = path,
                        Name = bundleName,
                        Version = assembly.GetName().Version,
                        State = BundleState.Installed
                    };

                    // and then, register it
                    context.RegisterBundle(bundleInfo);
                }
            }
        }
        public static void Start(IBundleContext context, string bundleName)
        {
            // load all installed bundle
            RefreshAllBundles(context);

            // TODO : handle installation of new bundle?
            var bundleInfo = context.GetBundle(bundleName);
            if(bundleInfo == null)
                throw new BundleNotFoundException(bundleName, null);

            if (bundleInfo.State == BundleState.Active)
            {
                logger.InfoFormat("Application {0} already loaded", bundleName);
                return;
            }

            AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
            setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            ApplicationIdentity identity = new ApplicationIdentity(bundleInfo.Name);
            //setup.ActivationArguments = new ActivationArguments(identity, new string[] { p });
            setup.ApplicationName = bundleInfo.Path;

            setup.AppDomainInitializer = null;
            //setup.AppDomainInitializer = new AppDomainInitializer(Initialize);
            //setup.AppDomainInitializerArguments = new string[]{ path };

            List<string> paths = new List<string>();
            paths.Add(Path.GetDirectoryName(bundleInfo.Path));
            paths.Add(Path.Combine(setup.ApplicationBase, "Libs"));
            paths.AddRange(Directory.GetDirectories(Path.Combine(setup.ApplicationBase, "Libs")));
            setup.PrivateBinPath = string.Join(";", paths.ToArray());

            var dom = AppDomain.CreateDomain(bundleInfo.Path, AppDomain.CurrentDomain.Evidence, setup);

            dom.ProcessExit += new EventHandler(dom_ProcessExit);
            dom.DomainUnload += new EventHandler(dom_DomainUnload);
            dom.UnhandledException += new UnhandledExceptionEventHandler(dom_UnhandledException);

            bundleInfo.Boostrap = (BundleController)dom.CreateInstanceAndUnwrap(typeof(BundleController).Assembly.FullName, typeof(BundleController).FullName);
            bundleInfo.AppDomain = dom;

            bundleInfo.State = BundleState.Resolved;
            context.RegisterBundle(bundleInfo);

            bundleInfo.Boostrap.StartActivator(context);
        }