EAS.Net 在程序里配置组件

public class BeforStart
    {
        /// <summary>
        /// 程序配置初始化
        /// </summary>
        public static void EASConfig()
        {
            #region 系统日志
            ComponentInfo Log = new ComponentInfo();
            Log.Name = "Logger";
            Log.Type = "EAS.Services.TextLogger";
            Log.Assembly = "EAS.MicroKernel";
            Log.Lifestyle = EAS.Objects.Lifecycle.LifestyleType.Singleton;
            ComponentConfig.Components.Add(Log.Name, Log);
            #endregion

            #region 系统资源
            ComponentInfo Component = new ComponentInfo();
            Component.Name = "EAS.Explorer.Resource";
            Component.Type = "System.Res.Resources";
            Component.Assembly = "System.Res";
            Component.Lifestyle = EAS.Objects.Lifecycle.LifestyleType.Singleton;
            ComponentConfig.Components.Add(Component.Name, Component);
            #endregion

            #region 服务桥
            ComponentInfo ServiceBridger = new ComponentInfo();
            ServiceBridger.Name = "ServiceBridger";
            ServiceBridger.Type = "EAS.Distributed.ServiceBridger";
            ServiceBridger.Assembly = "EAS.Distributed.Client";
            ServiceBridger.Lifestyle = EAS.Objects.Lifecycle.LifestyleType.Thread;
            PropertyInfo BridgerProperty = new PropertyInfo();
            BridgerProperty.Name = "ServiceName";
            BridgerProperty.Type = "string";
            BridgerProperty.Expression = "EAS.RMIService.Service";
            ServiceBridger.Properties.Add(BridgerProperty.Name, BridgerProperty);
            ComponentConfig.Components.Add(ServiceBridger.Name, ServiceBridger);
            #endregion

            #region 通用数据访问
            ComponentInfo DataAccessor = new ComponentInfo();
            DataAccessor.Name = "DataAccessor";
            DataAccessor.Type = "EAS.Distributed.DataAccessor";
            DataAccessor.Assembly = "EAS.Distributed.Client";
            DataAccessor.Lifestyle = EAS.Objects.Lifecycle.LifestyleType.Thread;
            PropertyInfo DataAccessorProperty = new PropertyInfo();
            DataAccessorProperty.Name = "ServiceBridger";
            DataAccessorProperty.Type = "object";
            DataAccessorProperty.Expression = "ServiceBridger";
            DataAccessor.Properties.Add(DataAccessorProperty.Name, DataAccessorProperty);
            ComponentConfig.Components.Add(DataAccessor.Name, DataAccessor);
            #endregion

            #region ORM访问组件
            ComponentInfo OrmAccessor = new ComponentInfo();
            OrmAccessor.Name = "OrmAccessor";
            OrmAccessor.Type = "EAS.Distributed.OrmAccessor";
            OrmAccessor.Assembly = "EAS.Distributed.Client";
            OrmAccessor.Lifestyle = EAS.Objects.Lifecycle.LifestyleType.Thread;

            PropertyInfo OrmBridgerProperty = new PropertyInfo();
            OrmBridgerProperty.Name = "ServiceBridger";
            OrmBridgerProperty.Type = "object";
            OrmBridgerProperty.Expression = "ServiceBridger";
            OrmAccessor.Properties.Add(OrmBridgerProperty.Name, OrmBridgerProperty);

            PropertyInfo OrmDACProperty = new PropertyInfo();
            OrmDACProperty.Name = "DataAccessor";
            OrmDACProperty.Type = "object";
            OrmDACProperty.Expression = "DataAccessor";
            OrmAccessor.Properties.Add(OrmDACProperty.Name, OrmDACProperty);
            ComponentConfig.Components.Add(OrmAccessor.Name, OrmAccessor);
            #endregion
        }
    }


再程序执行前 执行BeforStart.EASConfig();

配置文件中只需要保留很少一部分信息

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="eas" type="EAS.ConfigHandler,EAS.MicroKernel" />
    </configSections>
    <!--SQLite运行必需-->
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" />
    </startup>
    <eas>
        <configurations>
            <item name="WorkstationUser" value="Administrator" />
            <item name="LastUser" value="Administrator" />
        </configurations>
        <services>
            <service name="EAS.RMIService.Service" service-type="WcfService" singleton="true" url="http://localhost:8888/eas/services/EAS.RMIService" />
        </services>
    </eas>
</configuration>


 

 

posted @ 2013-06-25 15:39  docomo  阅读(559)  评论(0编辑  收藏  举报