Add IConfiguration constructors to Storage and Endpoint configuration

features/nuget_autobuild
Matija Koželj 2 years ago
parent d2d1f66cf6
commit 8fe51a15d5

@ -8,11 +8,9 @@ internal class ConfigurationService : IConfigurationService
{
public ConfigurationService(IConfiguration configuration)
{
Endpoint = new EndpointConfiguration();
configuration.Bind("endpoint", Endpoint);
Endpoint = new EndpointConfiguration(configuration.GetSection("endpoint"));
Storage = new StorageConfiguration();
configuration.Bind("storage", Storage);
Storage = new StorageConfiguration(configuration.GetSection("storage"));
}
public IEndpointConfiguration Endpoint { get; }

@ -1,19 +1,18 @@
using System.Collections.Immutable;
using Microsoft.Extensions.Configuration;
namespace Connected.Configuration
{
internal class DatabaseConfiguration : IDatabaseConfiguration
{
private List<string> _shards;
private readonly List<string> _shards;
public DatabaseConfiguration()
public DatabaseConfiguration(IConfiguration configuration)
{
/*
* TODO: read from config
*/
DefaultConnectionString = "server=PIT-ZBOOK\\sqlexpress; database=connected; trusted_connection=true;TrustServerCertificate=True;multiple active result sets=true";
DefaultConnectionString = "";
_shards = new();
configuration.Bind(this);
configuration.Bind("shards", _shards);
}
public string? DefaultConnectionString { get; init; }

@ -1,7 +1,14 @@
namespace Connected.Configuration.Endpoints
using Microsoft.Extensions.Configuration;
namespace Connected.Configuration.Endpoints
{
internal sealed class EndpointConfiguration : IEndpointConfiguration
{
public EndpointConfiguration(IConfiguration configuration)
{
configuration.Bind(this);
}
public string? Address { get; set; }
}
}

@ -4,7 +4,7 @@ namespace Connected.Configuration
{
public interface IDatabaseConfiguration
{
string DefaultConnectionString { get; }
string? DefaultConnectionString { get; }
ImmutableList<string> Shards { get; }
}

@ -1,10 +1,12 @@
namespace Connected.Configuration
using Microsoft.Extensions.Configuration;
namespace Connected.Configuration
{
internal class StorageConfiguration : IStorageConfiguration
{
public StorageConfiguration()
public StorageConfiguration(IConfiguration configuration)
{
Databases = new DatabaseConfiguration();
Databases = new DatabaseConfiguration(configuration.GetSection("databases"));
}
public IDatabaseConfiguration Databases { get; }

Loading…
Cancel
Save