Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="cdmdotnet Limited">
4 : // // Copyright cdmdotnet Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using cdmdotnet.Logging;
11 : using Cqrs.Configuration;
12 :
13 : namespace Cqrs.MongoDB.Events
14 : {
15 : public class MongoDbEventStoreConnectionStringFactory : IMongoDbEventStoreConnectionStringFactory
16 0 : {
17 : public static string MongoDbConnectionStringKey = "CqrsMongoDbEventStore";
18 :
19 : public static string MongoDbDatabaseNameKey = "CqrsMongoDbEventStoreDatabaseName";
20 :
21 : protected IConfigurationManager ConfigurationManager { get; private set; }
22 :
23 : protected ILogger Logger { get; private set; }
24 :
25 0 : public MongoDbEventStoreConnectionStringFactory(IConfigurationManager configurationManager, ILogger logger)
26 : {
27 : ConfigurationManager = configurationManager;
28 : Logger = logger;
29 : }
30 :
31 : #region Implementation of IMongoDbEventStoreConnectionStringFactory
32 :
33 0 : public string GetEventStoreConnectionString()
34 : {
35 : Logger.LogDebug("Getting MongoDB connection string", "MongoDbEventStoreConnectionStringFactory\\GetEventStoreConnectionString");
36 : try
37 : {
38 : return ConfigurationManager.GetSetting(MongoDbConnectionStringKey) ?? System.Configuration.ConfigurationManager.ConnectionStrings[MongoDbConnectionStringKey].ConnectionString;
39 : }
40 : catch (NullReferenceException exception)
41 : {
42 : throw new NullReferenceException(string.Format("No connection string named '{0}' in the configuration file.", MongoDbConnectionStringKey), exception);
43 : }
44 : finally
45 : {
46 : Logger.LogDebug("Getting MongoDB connection string... Done", "MongoDbEventStoreConnectionStringFactory\\GetEventStoreConnectionString");
47 : }
48 : }
49 :
50 0 : public string GetEventStoreDatabaseName()
51 : {
52 : return ConfigurationManager.GetSetting(MongoDbDatabaseNameKey);
53 : }
54 :
55 : #endregion
56 : }
57 : }
|