PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Bifrost/Configuration/ConfigSection/ConfigConfigurationSource.cs

#
C# | 75 lines | 43 code | 6 blank | 26 comment | 10 complexity | bd798991ce22f2523941d5eeac3f6e60 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. #region License
  2. //
  3. // Copyright (c) 2008-2012, DoLittle Studios and Komplett ASA
  4. //
  5. // Licensed under the Microsoft Permissive License (Ms-PL), Version 1.1 (the "License")
  6. // With one exception :
  7. // Commercial libraries that is based partly or fully on Bifrost and is sold commercially,
  8. // must obtain a commercial license.
  9. //
  10. // You may not use this file except in compliance with the License.
  11. // You may obtain a copy of the license at
  12. //
  13. // http://bifrost.codeplex.com/license
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //
  21. #endregion
  22. using System.Reflection;
  23. using Bifrost.Configuration.Xml;
  24. using Bifrost.Entities;
  25. namespace Bifrost.Configuration.ConfigSection
  26. {
  27. /// <summary>
  28. /// Represents an implementation of <see cref="IConfigurationSource"/> that works with App.config/web.config
  29. /// </summary>
  30. public class ConfigConfigurationSource : IConfigurationSource
  31. {
  32. readonly IConfigurationManager _configurationManager;
  33. /// <summary>
  34. /// Initializes an instance of <see cref="ConfigConfigurationSource"/>
  35. /// </summary>
  36. /// <param name="configurationManager"><see cref="IConfigurationManager"/> that is used to get the config section from</param>
  37. public ConfigConfigurationSource(IConfigurationManager configurationManager)
  38. {
  39. _configurationManager = configurationManager;
  40. }
  41. #pragma warning disable 1591 // Xml Comments
  42. public void Initialize(Configure configure)
  43. {
  44. var section = _configurationManager.GetSection("BifrostConfig") as BifrostConfig;
  45. if( section != null )
  46. {
  47. if( section.Commands != null )
  48. {
  49. }
  50. if( section.DefaultStorage != null )
  51. {
  52. var configuration = section.DefaultStorage.GetConfiguration();
  53. configure.Container.Bind<IEntityContextConfiguration>(configuration);
  54. configure.Container.Bind(configuration.Connection.GetType(), configuration.Connection);
  55. configure.Container.Bind(typeof(IEntityContext<>), section.DefaultStorage.EntityContextType);
  56. }
  57. if( section.Events != null )
  58. {
  59. configure.Events.RepositoryType = section.Events.RepositoryType;
  60. }
  61. if( section.Sagas != null )
  62. {
  63. configure.Sagas.LibrarianType = section.Sagas.LibrarianType;
  64. }
  65. }
  66. }
  67. #pragma warning restore 1591 // Xml Comments
  68. }
  69. }