50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Configuration;
|
|
|
|
namespace Kreta.Naplo.Configuration
|
|
{
|
|
public class CorsConfiguration : ConfigurationSection, ICorsConfiguration
|
|
{
|
|
const string SectionName = "CorsConfiguration";
|
|
|
|
static Lazy<CorsConfiguration> instance;
|
|
|
|
public static CorsConfiguration Instance
|
|
{
|
|
get
|
|
{
|
|
return instance.Value;
|
|
}
|
|
}
|
|
|
|
[ConfigurationProperty(nameof(IsEnabled), IsRequired = true)]
|
|
public bool IsEnabled => (bool)this[nameof(IsEnabled)];
|
|
|
|
[ConfigurationProperty(nameof(Urls), IsRequired = true)]
|
|
public string Urls => (string)this[nameof(Urls)];
|
|
|
|
[ConfigurationProperty(nameof(Headers), IsRequired = true)]
|
|
public string Headers => (string)this[nameof(Headers)];
|
|
|
|
[ConfigurationProperty(nameof(Methods), IsRequired = true)]
|
|
public string Methods => (string)this[nameof(Methods)];
|
|
|
|
[ConfigurationProperty(nameof(SupportsCredentials), IsRequired = true)]
|
|
public bool SupportsCredentials => (bool)this[nameof(SupportsCredentials)];
|
|
|
|
static CorsConfiguration()
|
|
{
|
|
instance = new Lazy<CorsConfiguration>(() =>
|
|
{
|
|
var section = (CorsConfiguration)ConfigurationManager.GetSection(SectionName);
|
|
|
|
if (section == null)
|
|
{
|
|
throw new ConfigurationErrorsException($"{SectionName} configuration section was not found");
|
|
}
|
|
|
|
return section;
|
|
});
|
|
}
|
|
}
|
|
}
|