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) public ConfigurationService(IConfiguration configuration)
{ {
Endpoint = new EndpointConfiguration(); Endpoint = new EndpointConfiguration(configuration.GetSection("endpoint"));
configuration.Bind("endpoint", Endpoint);
Storage = new StorageConfiguration(); Storage = new StorageConfiguration(configuration.GetSection("storage"));
configuration.Bind("storage", Storage);
} }
public IEndpointConfiguration Endpoint { get; } public IEndpointConfiguration Endpoint { get; }

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

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

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

Loading…
Cancel
Save