Line data Source code
1 : using System;
2 : using Cqrs.Configuration;
3 : using cdmdotnet.Logging;
4 :
5 : namespace Cqrs.Mongo.Factories
6 : {
7 : public class MongoDataStoreConnectionStringFactory : IMongoDataStoreConnectionStringFactory
8 0 : {
9 : public static string MongoDbConnectionStringKey = "CqrsMongoDb";
10 :
11 : public static string MongoDbDatabaseNameKey = "CqrsMongoDbDatabaseName";
12 :
13 : protected IConfigurationManager ConfigurationManager { get; private set; }
14 :
15 : protected ILogger Logger { get; private set; }
16 :
17 0 : public MongoDataStoreConnectionStringFactory(IConfigurationManager configurationManager, ILogger logger)
18 : {
19 : ConfigurationManager = configurationManager;
20 : Logger = logger;
21 : }
22 :
23 0 : public string GetMongoConnectionString()
24 : {
25 : Logger.LogInfo("Getting MongoDB connection string", "MongoDataStoreConnectionStringFactory\\GetMongoConnectionString");
26 : try
27 : {
28 : return ConfigurationManager.GetSetting(MongoDbConnectionStringKey) ?? System.Configuration.ConfigurationManager.ConnectionStrings[MongoDbConnectionStringKey].ConnectionString;
29 : }
30 : catch (NullReferenceException exception)
31 : {
32 : throw new NullReferenceException(string.Format("No connection string named '{0}' in the configuration file.", MongoDbConnectionStringKey), exception);
33 : }
34 : finally
35 : {
36 : Logger.LogDebug("Getting MongoDB connection string... Done", "MongoDataStoreConnectionStringFactory\\GetMongoConnectionString");
37 : }
38 : }
39 :
40 0 : public string GetMongoDatabaseName()
41 : {
42 : return ConfigurationManager.GetSetting(MongoDbDatabaseNameKey);
43 : }
44 : }
45 : }
|