PageRenderTime 77ms CodeModel.GetById 74ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 75 lines | 43 code | 6 blank | 26 comment | 10 complexity | bd798991ce22f2523941d5eeac3f6e60 MD5 | raw file
 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
23using System.Reflection;
24using Bifrost.Configuration.Xml;
25using Bifrost.Entities;
26
27namespace Bifrost.Configuration.ConfigSection
28{
29	/// <summary>
30	/// Represents an implementation of <see cref="IConfigurationSource"/> that works with App.config/web.config
31	/// </summary>
32	public class ConfigConfigurationSource : IConfigurationSource
33    {
34		readonly IConfigurationManager _configurationManager;
35
36		/// <summary>
37		/// Initializes an instance of <see cref="ConfigConfigurationSource"/>
38		/// </summary>
39		/// <param name="configurationManager"><see cref="IConfigurationManager"/> that is used to get the config section from</param>
40		public ConfigConfigurationSource(IConfigurationManager configurationManager)
41		{
42			_configurationManager = configurationManager;
43		}
44
45#pragma warning disable 1591 // Xml Comments
46		public void Initialize(Configure configure)
47        {
48            var section = _configurationManager.GetSection("BifrostConfig") as BifrostConfig;
49            if( section != null )
50            {
51                if( section.Commands != null )
52                {
53                    
54                }
55                if( section.DefaultStorage != null )
56                {
57                    var configuration = section.DefaultStorage.GetConfiguration();
58                    configure.Container.Bind<IEntityContextConfiguration>(configuration);
59                    configure.Container.Bind(configuration.Connection.GetType(), configuration.Connection);
60                    configure.Container.Bind(typeof(IEntityContext<>), section.DefaultStorage.EntityContextType);
61                }
62
63                if( section.Events != null )
64                {
65                    configure.Events.RepositoryType = section.Events.RepositoryType;
66                }
67				if( section.Sagas != null )
68				{
69					configure.Sagas.LibrarianType = section.Sagas.LibrarianType;
70				}
71            }
72		}
73#pragma warning restore 1591 // Xml Comments
74	}
75}