public void MultiSourceTest()
        {
            DynamicProperties.Instance = null;
            var properties = (DynamicProperties)DynamicProperties.Init(1);

            var source1 = new StaticConfigurationSource();

            properties.RegisterSource(source1);

            var source2 = new StaticConfigurationSource();

            properties.RegisterSource(source2);

            var prop = properties.GetOrCreateProperty <int>("test30");

            Assert.Equal(0, prop.Value);

            source1.Set("test30", 10);
            Thread.Sleep(properties.PollingIntervalInSeconds * 1100);
            Assert.Equal(10, prop.Value);

            source2.Set("test30", 20);
            Thread.Sleep(properties.PollingIntervalInSeconds * 1100);
            Assert.Equal(20, prop.Value);
        }
        public void ChainedSourceTest()
        {
            DynamicProperties.Instance = null;
            var properties = DynamicProperties.Init(1);

            var source = new StaticConfigurationSource();

            ((DynamicProperties)properties).RegisterSource(source);

            var chained = properties.Factory.AsChainedProperty("test10", 30, "test20");

            Assert.Equal(30, properties.Factory.AsChainedProperty("test10", 30, "test20").Value);

            source.Set("test20", 20);
            Thread.Sleep(properties.PollingIntervalInSeconds * 1200);
            Assert.Equal(20, chained.Value);

            source.Set("test10", 10);
            Thread.Sleep(properties.PollingIntervalInSeconds * 1100);
            Assert.Equal(10, chained.Value);

            source.Set("test10", 11);
            Thread.Sleep(properties.PollingIntervalInSeconds * 1100);
            Assert.Equal(11, chained.Value);
        }
        public static void Main()
        {
            DynamicProperties.Init(pollingIntervalInSeconds: 10)
            .WithSources()
            .AddSource(new HttpConfigurationSource("http://localhost:5000"))
            .Initialize();

            var prop1 = DynamicProperties.Instance.GetOrCreateProperty <bool>("sample.prop1");
            var prop2 = DynamicProperties.Instance.GetOrCreateProperty <int>("sample.prop2");
            var prop3 = DynamicProperties.Instance.GetOrCreateProperty <string>("sample.prop3");
            var prop4 = DynamicProperties.Factory.AsProperty(50L);

            // Add "sample.prop5": 20 in the properties.json file on the server side
            var prop5 = DynamicProperties.Factory.AsChainedProperty("sample.prop5", 0L, "sample.prop2");

            do
            {
                Console.WriteLine($"prop1={prop1}");
                Console.WriteLine($"prop2={prop2}");
                Console.WriteLine($"prop3={prop3}");
                Console.WriteLine($"prop4={prop4}");
                Console.WriteLine($"prop5={prop5}");
                Console.ReadKey();
            }while (true);
        }
        public void SourceDeclarationTest()
        {
            DynamicProperties.Instance = null;
            var properties = (DynamicProperties)DynamicProperties.Init(1);

            var source = new StaticConfigurationSource();

            properties.RegisterSource(source);

            var prop = properties.GetProperty <int>("test");

            Assert.Null(prop);

            source.Set("test", 10);
            prop = properties.GetProperty <int>("test");
            Assert.Null(prop);

            Thread.Sleep(properties.PollingIntervalInSeconds * 1100);

            prop = properties.GetProperty <int>("test");
            Assert.NotNull(prop);
            Assert.Equal(10, prop.Value);
        }
 public static ConfigurationSourceBuilder UseDynamicProperties(this IServiceCollection services)
 {
     DynamicProperties.Init();
     services.AddSingleton <IDynamicProperties>(s => DynamicProperties.Instance);
     return(DynamicProperties.Instance.WithSources());
 }