/// <summary>
        /// Register dependencies
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterDependencies(RxLocalConfig config)
        {
            var builder = new ContainerBuilder();

            // Register dependencies
            var typeFinder = new WebAppTypeFinder(config);

            builder = new ContainerBuilder();

            builder.RegisterInstance(config).As <RxLocalConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            // Register any dependencies provided by other assemblies
            var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar>();
            var drInstances = drTypes.Select(drType => (IDependencyRegistrar)Activator.CreateInstance(drType)).ToList();

            // Order the dependency registrars by priority
            drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in drInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder);
            }


            var container = builder.Build();

            this._containerManager = new ContainerManager(container);

            // Set the dependency resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
        /// <summary>
        /// Initialize components and plugins in the RxLocal environment.
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(RxLocalConfig config)
        {
            //register dependencies
            RegisterDependencies(config);

            //startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks();
            }
        }
        /// <summary>
        /// Creates a factory instance and adds a http application injecting facility.
        /// </summary>
        /// <param name="config">Config</param>
        /// <returns>New engine instance</returns>
        protected static IEngine CreateEngineInstance(RxLocalConfig config)
        {
            if (config != null && !string.IsNullOrEmpty(config.EngineType))
            {
                var engineType = Type.GetType(config.EngineType);
                if (engineType == null)
                {
                    throw new ConfigurationErrorsException("The type '" + config.EngineType + "' could not be found. Please check the configuration at /configuration/RxLocal/engine[@engineType] or check for missing assemblies.");
                }
                if (!typeof(IEngine).IsAssignableFrom(engineType))
                {
                    throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'RxLocal.Core.Infrastructure.IEngine' and cannot be configured in /configuration/RxLocal/engine[@engineType] for that purpose.");
                }
                return(Activator.CreateInstance(engineType) as IEngine);
            }

            return(new RxLocalEngine());
        }
 public WebAppTypeFinder(RxLocalConfig config)
 {
     this.EnsureBinFolderAssembliesLoaded = config.DynamicDiscovery;
 }