/// <summary> /// 初始化组件和插件的HCHE环境。 /// </summary> /// <param name="config">Config</param> public void Initialize(HCConfig config) { //bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled(); // if (databaseInstalled) //{ //启动任务 //RunStartupTasks(); //} if (!config.IgnoreStartupTasks) { RunStartupTasks(); } }
/// <summary> /// 根据配置去实现最初的 new实例化 如果没有配置则初始化new一个默认的 /// </summary> /// <param name="config"></param> /// <returns></returns> public static IEngine CreateEngineInstance(HCConfig config) { if (config != null && !string.IsNullOrEmpty(config.EngineType)) { var engineType = Type.GetType(config.EngineType); if (engineType == null) { throw new Exception("类型 '" + engineType + "' 没有找到. 请检查配置文件 /configuration/eisms/engine[@engineType] 或检查是否缺少程序集."); } if (!typeof(IEngine).IsAssignableFrom(engineType)) { throw new Exception("类型 '" + engineType + "' 不能执行 'EISMS.Core.Infrastructure.IEngine' 并且在 /configuration/eisms/engine[@engineType] 不能配置用于这一目的."); } return(Activator.CreateInstance(engineType) as IEngine);//根据config文件配置去 反射一个实例 } return(new HCEngine()); }
///// <summary> ///// 已知配置密钥配置服务 ///// </summary> //public static class ConfigurationKeys //{ // /// <summary>中等信任.</summary> // public const string MediumTrust = "MediumTrust"; // /// <summary>完全信任.</summary> // public const string FullTrust = "FullTrust"; //} //public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, HCConfig configuration) //{ // //其它依赖 // containerManager.AddComponentInstance<HCConfig>(configuration, "HC.configuration"); // containerManager.AddComponentInstance<IEngine>(engine, "HC.engine"); // containerManager.AddComponentInstance<ContainerConfigurer>(this, "HC.containerConfigurer"); // //类型查找 // containerManager.AddComponent<ITypeFinder, WebAppTypeFinder>("HC.typeFinder"); // //提供其它程序集注册的依赖关系 // var typeFinder = containerManager.Resolve<ITypeFinder>(); // containerManager.UpdateContainer(x => // { // var drTypes = typeFinder.FindClassesOfType<IDependencyRegistrar>(); // var drInstances = new List<IDependencyRegistrar>(); // foreach (var drType in drTypes) // drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType)); // //排序 // drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); // //drInstances = drInstances.AsQueryable().ToList(); // foreach (var dependencyRegistrar in drInstances) // dependencyRegistrar.Register(x, typeFinder); // }); // //事件代理 // containerManager.AddComponentInstance(broker); // //注册服务 // containerManager.AddComponent<DependencyAttributeRegistrator>("HC.serviceRegistrator"); // var registrator = containerManager.Resolve<DependencyAttributeRegistrator>(); // var services = registrator.FindServices(); // var configurations = GetComponentConfigurations(configuration); // services = registrator.FilterServices(services, configurations); // registrator.RegisterServices(services); //} //// <summary> ///// 获取组件配置信息 ///// </summary> ///// <param name="configuration"></param> ///// <returns></returns> //protected virtual string[] GetComponentConfigurations(HCConfig configuration) //{ // var configurations = new List<string>(); // string trustConfiguration = (CommonHelper.GetTrustLevel() > System.Web.AspNetHostingPermissionLevel.Medium) // ? ConfigurationKeys.FullTrust // : ConfigurationKeys.MediumTrust; // configurations.Add(trustConfiguration); // return configurations.ToArray(); //} public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, HCConfig configuration) { //other dependencies containerManager.AddComponentInstance <HCConfig>(configuration, "nop.configuration"); containerManager.AddComponentInstance <IEngine>(engine, "nop.engine"); containerManager.AddComponentInstance <ContainerConfigurer>(this, "nop.containerConfigurer"); //type finder containerManager.AddComponent <ITypeFinder, WebAppTypeFinder>("nop.typeFinder"); //register dependencies provided by other assemblies var typeFinder = containerManager.Resolve <ITypeFinder>(); containerManager.UpdateContainer(x => { var drTypes = typeFinder.FindClassesOfType <IDependencyRegistrar>(); var drInstances = new List <IDependencyRegistrar>(); foreach (var drType in drTypes) { drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType)); } //sort drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) { dependencyRegistrar.Register(x, typeFinder); } }); //event broker containerManager.AddComponentInstance(broker); }
/// <summary> /// 初始化容器 /// </summary> /// <param name="configurer"></param> /// <param name="broker"></param> /// <param name="config"></param> private void InitializeContainer(ContainerConfigurer configurer, EventBroker broker, HCConfig config) { var builder = new ContainerBuilder(); _containerManager = new ContainerManager(builder.Build()); configurer.Configure(this, _containerManager, broker, config); }
public WebAppTypeFinder(HCConfig config) { this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery; }
public ThemeProvider(HCConfig eismsConfig, IWebHelper webHelper) { basePath = webHelper.MapPath(eismsConfig.ThemeBasePath); LoadConfigurations(); }