コード例 #1
0
        public static T Register <T>()
        {
            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager = new ChoCoreFrxConfigurationManager <T>())
            {
                T instance = coreFrxConfigurationManager.ConfigObject;

                if (instance is IChoObjectChangeWatcheable)
                {
                    if (!ChoAppFrxSettings.Me.DisableFrxConfig)
                    {
                        ChoConfigurationChangeFileWatcher fileWatcher = null;
                        fileWatcher = new ChoConfigurationChangeFileWatcher("{0}_FileWatcher".FormatString(typeof(T).Name), coreFrxConfigurationManager.ConfigFilePath);
                        fileWatcher.DoNotUseGlobalQueue = true;
                        fileWatcher.SetConfigurationChangedEventHandler("{0}_FileWatcher".FormatString(typeof(T).Name), (sender1, e1) =>
                        {
                            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager1 = new ChoCoreFrxConfigurationManager <T>())
                            {
                                T instance1 = coreFrxConfigurationManager1.ConfigObject;
                                if (instance1 is IChoObjectChangeWatcheable)
                                {
                                    ((IChoObjectChangeWatcheable)instance1).OnObjectChanged(instance1, null);
                                }
                            }
                        });

                        _dictService.AddOrUpdate(typeof(T), fileWatcher);

                        ChoEnvironmentSettings.SetEnvironmentChangedEventHandlerNoCall(typeof(T).Name, ((sender, e) =>
                        {
                            using (ChoCoreFrxConfigurationManager <T> coreFrxConfigurationManager1 = new ChoCoreFrxConfigurationManager <T>())
                            {
                                T instance1 = coreFrxConfigurationManager1.ConfigObject;
                                if (instance1 is IChoObjectChangeWatcheable)
                                {
                                    ((IChoObjectChangeWatcheable)instance1).OnObjectChanged(instance1, null);
                                }
                            }
                        }));

                        if (fileWatcher != null)
                        {
                            fileWatcher.StartWatching();
                        }
                    }
                }

                return(instance);
            }
        }
コード例 #2
0
 static ChoConfigurationChangeWatcherSettings()
 {
     ChoSingletonFactoryService.Register(typeof(ChoConfigurationChangeWatcherSettings), () => ChoCoreFrxConfigurationManager.Register <ChoConfigurationChangeWatcherSettings>());
 }