Click here to Skip to main content
15,895,084 members
Articles / Programming Languages / C#

ObjectLounge - An Object-Oriented Database Framework

Rate me:
Please Sign up or sign in to vote.
4.07/5 (8 votes)
30 Jul 2009LGPL310 min read 44K   425   45  
Host your Domain Models "Out Of The Box" + No storage or schema needed + Transactions on Domain Models + Validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Technewlogic.ObjectLounge.Framework.MetaModel
{
	// TODO: Tests für das automatische Injecten von Entity Collections schreiben
	public class ApplicationContextSpec
	{
		internal ApplicationContextSpec(
			ModelConfigurationErrorManager errorManager,
			Type contextType)
		{
			_errorManager = errorManager;
			ContextType = contextType;

			BuildApplicationContextCollectionSpecs();
		}

		private readonly ModelConfigurationErrorManager _errorManager;

		public Type ContextType { get; private set; }
		public IEnumerable<ApplicationContextCollectionSpec> ApplicationContextCollectionSpecs { get; private set; }

		public IEnumerable<Type> RegisteredTypes
		{
			get
			{
				return ApplicationContextCollectionSpecs
					.Select(it => it.EntityType);
			}
		}

		private void BuildApplicationContextCollectionSpecs()
		{
			var contextCollectionProperties = GetContextCollectionProperties();

			ApplicationContextCollectionSpecs = contextCollectionProperties
				.Select(it => new ApplicationContextCollectionSpec(_errorManager, it))
				.ToArray();

			var redundantModelTypes = ApplicationContextCollectionSpecs
				.GroupBy(it => it.EntityType)
				.Where(it => it.Count() > 1);
			foreach (var it in redundantModelTypes)
				_errorManager.ModelTypeRegisteredRedundant(it.Key);
		}

		#region Helper

		private IEnumerable<PropertyInfo> GetContextCollectionProperties()
		{
			var contextCollectionProperties = ContextType
				.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
				.Select(it => new
				{
					PropertyInfo = it,
					EntityCollectionAttribute = it
						.GetCustomAttributes(typeof(EntityCollectionAttribute), true)
						.FirstOrDefault()
				})
				.Where(it => it.EntityCollectionAttribute != null)
				.Select(it => it.PropertyInfo);

			return contextCollectionProperties;
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) www.technewlogic.de
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions