Skip to content

Commit

Permalink
Simplified Configuration
Browse files Browse the repository at this point in the history
Removed redudant provider collection - database and certificates and
moved them to main configuration node
  • Loading branch information
punitganshani committed Dec 21, 2014
1 parent ebb004b commit a11f04d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 271 deletions.
12 changes: 9 additions & 3 deletions Server/KonfDB.Infrastructure/Configuration/HostConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using KonfDB.Infrastructure.Configuration.Caching;
using KonfDB.Infrastructure.Configuration.Interfaces;
using KonfDB.Infrastructure.Configuration.Providers;
using KonfDB.Infrastructure.Configuration.Providers.Certificate;
using KonfDB.Infrastructure.Configuration.Providers.Database;
using KonfDB.Infrastructure.Configuration.Runtime;
using Newtonsoft.Json;

Expand All @@ -39,14 +41,18 @@ internal class HostConfig : IHostConfig
[JsonProperty("cache")]
public CacheConfigurationSection Caching { get; private set; }

[JsonProperty("providers")]
public ProvidersConfiguration Providers { get; private set; }
[JsonProperty("database")]
public DatabaseProviderCollection Database { get; set; }

[JsonProperty("certificates")]
public CertificateProviderCollection Certificate { get; set; }

public HostConfig()
{
Runtime = new HostRuntimeConfiguration();
Caching = new CacheConfigurationSection();
Providers = new ProvidersConfiguration();
Database = new DatabaseProviderCollection();
Certificate = new CertificateProviderCollection();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

using KonfDB.Infrastructure.Configuration.Caching;
using KonfDB.Infrastructure.Configuration.Providers;
using KonfDB.Infrastructure.Configuration.Providers.Certificate;
using KonfDB.Infrastructure.Configuration.Providers.Database;
using KonfDB.Infrastructure.Configuration.Runtime;

namespace KonfDB.Infrastructure.Configuration.Interfaces
Expand All @@ -33,6 +35,7 @@ internal interface IHostConfig
{
HostRuntimeConfiguration Runtime { get; }
CacheConfigurationSection Caching { get; }
ProvidersConfiguration Providers { get; }
DatabaseProviderCollection Database { get; set; }
CertificateProviderCollection Certificate { get; set; }
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions Server/KonfDB.Infrastructure/KonfDB.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<Compile Include="Attributes\IgnoreCacheAttribute.cs" />
<Compile Include="Configuration\Interfaces\IDatabaseProviderConfiguration.cs" />
<Compile Include="Configuration\Interfaces\IHostConfig.cs" />
<Compile Include="Configuration\Interfaces\IProvidersConfiguration.cs" />
<Compile Include="Configuration\Interfaces\IProviderTypeConfiguration.cs" />
<Compile Include="Configuration\Providers\Certificate\CertificateProviderCollection.cs" />
<Compile Include="Configuration\Providers\Certificate\CertificateProviderConfiguration.cs" />
Expand All @@ -121,7 +120,6 @@
<Compile Include="Common\Serializer.cs" />
<Compile Include="Configuration\Providers\Database\DatabaseProviderCollection.cs" />
<Compile Include="Configuration\Providers\Database\DatabaseProviderConfiguration.cs" />
<Compile Include="Configuration\Providers\ProvidersConfiguration.cs" />
<Compile Include="Configuration\HostConfig.cs" />
<Compile Include="Configuration\Providers\Types\ProviderTypeConfiguration.cs" />
<Compile Include="Configuration\Providers\Types\ProviderTypesCollection.cs" />
Expand Down
36 changes: 15 additions & 21 deletions Server/KonfDB.Infrastructure/Shell/CurrentHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using KonfDB.Infrastructure.Configuration.Interfaces;
using KonfDB.Infrastructure.Configuration.Runtime;
using KonfDB.Infrastructure.Database.Providers;
using KonfDB.Infrastructure.Exceptions;
using KonfDB.Infrastructure.Extensions;
using KonfDB.Infrastructure.Logging;
using KonfDB.Infrastructure.Services;
using KonfDB.Infrastructure.Utilities;
Expand Down Expand Up @@ -122,32 +124,24 @@ public List<AuthenticationOutput> GetUsers()

private BaseProvider GetDatabaseProviderInstance(IHostConfig configuration)
{
var defaultDatabaseConfig = configuration.Providers.Database.Default;
var providerTypesConfig = configuration.Providers.Types;
var defaultDatabaseConfig = configuration.Database.Default;
Type providerType = Type.GetType(defaultDatabaseConfig.ProviderType);

if (providerType == null)
throw new InvalidConfigurationException("Could not locate Database Provider :" + defaultDatabaseConfig.ProviderType);

if (!providerTypesConfig.IsValid(defaultDatabaseConfig.ProviderType))
throw new ConfigurationErrorsException("Provider type not found: " + defaultDatabaseConfig.ProviderType +
" for database provider: " +
defaultDatabaseConfig.Key);
var providerConfiguration = providerTypesConfig[defaultDatabaseConfig.ProviderType];
if (!providerType.ImplementsClass<BaseProvider>())
throw new InvalidConfigurationException("Database Provider does not implement BaseProvider:" + defaultDatabaseConfig.ProviderType);

Type providerType = Type.GetType(providerConfiguration.AssemblyPath);
if (providerType != null)
{
var instance = Activator.CreateInstance(providerType, defaultDatabaseConfig);
var instance = Activator.CreateInstance(providerType, defaultDatabaseConfig);

var baseProvider = instance as BaseProvider;
if (baseProvider != null)
{
baseProvider.Init();
return baseProvider;
}
throw new InvalidOperationException("Type : " + providerType + " does not inherit from BaseProvider");
var baseProvider = instance as BaseProvider;
if (baseProvider != null)
{
baseProvider.Init();
return baseProvider;
}

throw new InvalidOperationException(string.Format("Unknown Case: Could not get database provider for :{0}",
defaultDatabaseConfig.ProviderType));
throw new InvalidOperationException("Type : " + providerType + " does not inherit from BaseProvider");
}
}
}
2 changes: 1 addition & 1 deletion Server/KonfDBHost/KonfDBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected override void OnStart(string[] args)
{
var serviceSecurity = new ServiceSecurity
{
CertificateConfiguration = CurrentHostContext.Default.Config.Providers.Certificate.Default,
CertificateConfiguration = CurrentHostContext.Default.Config.Certificate.Default,
SecurityMode = CurrentHostContext.Default.Config.Runtime.ServiceSecurity
};

Expand Down
Loading

0 comments on commit a11f04d

Please sign in to comment.