예제 #1
0
        private static IServiceLocator Setup()
        {
            var            config  = ConfigHelper.LoadConfigSettingFromAssemblies(typeof(ServiceLocator).Assembly, null, null, null);
            StartupSetting setting = null;

            if (config != null)
            {
                config = config["htb.devfx"];
                if (config != null)
                {
                    setting = ConfigSetting.ToSetting <StartupSetting>(config, "startup");
                }
            }
            ServiceLocatorSetting locatorSetting = null;

            if (setting != null && setting.CoreSetting != null)
            {
                locatorSetting = setting.CoreSetting.ServiceLocatorSetting;
            }
            IServiceLocator instance = null;

            if (locatorSetting != null && !string.IsNullOrEmpty(locatorSetting.TypeName))
            {
                var typeName = locatorSetting.TypeName;
                instance = (IServiceLocator)TypeHelper.CreateObject(typeName, typeof(IServiceLocator), false);
            }
            if (instance == null)
            {
                instance = new ServiceLocatorInternal();
            }
            if (instance is IServiceLocatorInternal)
            {
                ((IServiceLocatorInternal)instance).Init(locatorSetting);
            }
            return(instance);
        }