Exemplo n.º 1
0
        public void Test_reference_equals_1(string filename)
        {
            var services = new ServiceCollection();

            var configuration        = ConfigurationTestBuilder.BuildFromEmbeddedResource(filename);
            var sectionName          = SettingsSectionNameAttribute.GetSettingsSectionName <AttributeValidatedSettings>();
            var configurationSection = configuration.GetSection(sectionName);

            // This is the standard way, it results in lazy validation
            services.AddOptions <AttributeValidatedSettings>()
            .Bind(configurationSection)
            .RecursivelyValidateDataAnnotations();

            var serviceProvider = services.BuildServiceProvider();

            var result1 = serviceProvider.GetRequiredService <IOptions <AttributeValidatedSettings> >().Value;
            var result2 = serviceProvider.GetRequiredService <IOptions <AttributeValidatedSettings> >().Value;

            Assert.True(object.ReferenceEquals(result1, result2));
        }