/// <summary>
        /// Get a new entity of the specified type.
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public object GetEntity(string typeFullName)
        {
            EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName);
            object entity = Activator.CreateInstance(ctx.EntityType);

            return(entity);
        }
        /// <summary>
        /// Get context object associated with the service of the specified type.
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public IActionContext GetContext(string typeFullName)
        {
            EntityRegistrationContext ctx           = EntityRegistration.GetRegistrationContext(typeFullName);
            IActionContext            actionContext = Activator.CreateInstance(ctx.ActionContextType) as IActionContext;

            return(actionContext);
        }
        /// <summary>
        /// Get the entity Service(supporting CRUD operations).
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public static object GetService(string typeFullName)
        {
            EntityRegistrationContext ctx = _managableEntities[typeFullName];

            // Singleton.
            if (ctx.IsSingletonService)
            {
                return(ctx.Service);
            }

            object service    = null;
            object repository = null;

            if (ctx.CreationMethod == EntityCreationType.Factory)
            {
                service = ctx.FactoryMethodForService();
                if (ctx.FactoryMethodForRepository != null)
                {
                    repository = ctx.FactoryMethodForRepository();
                }
                if (repository != null && ctx.IsRepositoryConfigurationRequired)
                {
                    RepositoryConfigurator.Configure((IRepositoryConfigurable)repository);
                }
            }
            else
            {
                service = _entityRegistrarIoc.GetService(typeFullName);
            }

            return(service);
        }
        /// <summary>
        /// Get the entity Service(supporting CRUD operations).
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public object GetService(string typeFullName)
        {
            EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName);
            string serviceName            = ctx.Name + EntityRegistrationConstants.SuffixService;
            object obj = Ioc.GetObject <object>(serviceName);

            return(obj);
        }
        /// <summary>
        /// Get an object from the IocContainer using the type's full name and a suffix.
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public object GetObject(string typeFullName, string suffix)
        {
            EntityRegistrationContext ctx = EntityRegistration.GetRegistrationContext(typeFullName);
            string entryName = ctx.Name + suffix;
            object obj       = Ioc.GetObject <object>(entryName);

            return(obj);
        }
        /// <summary>
        /// Get the Domain entity Service object that supports(CRUD) operations.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object GetValdiator(Type type)
        {
            EntityRegistrationContext ctx = _managableEntities[type.FullName];

            if (ctx.FactoryMethodForValidator != null)
            {
                return(ctx.FactoryMethodForValidator());
            }

            return(_entityRegistrarIoc.GetValidator(type.FullName));
        }
        /// <summary>
        /// Get the Domain entity Service object that supports(CRUD) operations.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object GetRepository(string typeFullName)
        {
            EntityRegistrationContext ctx = _managableEntities[typeFullName];

            // If factory method was supplied.
            if (ctx.FactoryMethodForRepository != null)
            {
                return(ctx.FactoryMethodForRepository());
            }

            return(_entityRegistrarIoc.GetRepository(typeFullName));
        }
 /// <summary>
 /// Registers the specified CTX for creating the components
 /// necessary for the DomainModel ActiveRecord.
 /// </summary>
 /// <param name="ctx">The CTX.</param>
 public static void Register(EntityRegistrationContext ctx)
 {
     if (!_managableEntities.ContainsKey(ctx.EntityType.FullName))
     {
         _managableEntities.Add(ctx.EntityType.FullName, ctx);
         _managableEntitiesList.Add(ctx.EntityType.FullName);
     }
     // Overwrite
     else
     {
         _managableEntities[ctx.EntityType.FullName] = ctx;
     }
     // Register.
     if (ctx.IsRepositoryConfigurationRequired && ctx.IsSingletonRepository)
     {
         RepositoryConfigurator.Configure((IRepositoryConfigurable)ctx.Repository);
     }
 }
        /// <summary>
        /// Registers the specified entity type to wire up ActiveRecord functionality.
        /// </summary>
        /// <param name="ctx">The CTX.</param>
        public static void Register(Type entityType, Func <object> serviceCreator, Func <object> repositoryCreator)
        {
            EntityRegistrationContext ctx = null;

            if (_managableEntities.ContainsKey(entityType.FullName))
            {
                ctx = _managableEntities[entityType.FullName];
            }
            else
            {
                ctx = new EntityRegistrationContext(entityType.Name, entityType, typeof(ActionContext));
            }

            // Setup the properties.
            ctx.CreationMethod             = EntityCreationType.Factory;
            ctx.FactoryMethodForService    = serviceCreator;
            ctx.FactoryMethodForRepository = repositoryCreator;
            Register(ctx);
        }
        /// <summary>
        /// Register a singleton service/repository for the entity specified by T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="service"></param>
        /// <param name="configureRepository"></param>
        public static void Register <T>(IEntityService <T> service, bool configureRepository)
        {
            EntityRegistrationContext ctx = new EntityRegistrationContext();

            ctx.EntityType                        = typeof(T);
            ctx.Name                              = typeof(T).FullName;
            ctx.IsSingletonService                = true;
            ctx.IsSingletonRepository             = true;
            ctx.Service                           = service;
            ctx.Repository                        = service.Repository;
            ctx.IsRepositoryConfigurationRequired = configureRepository;
            ctx.CreationMethod                    = EntityCreationType.Factory;
            ctx.ActionContextType                 = typeof(ActionContext <T>);

            if (ctx.IsRepositoryConfigurationRequired)
            {
                RepositoryConfigurator.Configure(service.Repository);
            }

            Register(ctx);
        }
        /// <summary>
        /// Initialize the service, repository creators.
        /// </summary>
        /// <param name="serviceCreator">The service creator.</param>
        /// <param name="repoCreator">The repository creator.</param>
        /// <param name="configureRepository">Whether or not to configure the reposiory.</param>
        public static void Register <T>(Func <IEntityService <T> > serviceCreator, Func <IEntityRepository <T> > repoCreator, Func <IEntityValidator <T> > validatorCreator, bool configureRepository)
        {
            EntityRegistrationContext ctx = new EntityRegistrationContext();

            ctx.EntityType                        = typeof(T);
            ctx.Name                              = typeof(T).FullName;
            ctx.IsSingletonService                = false;
            ctx.IsSingletonRepository             = false;
            ctx.IsRepositoryConfigurationRequired = configureRepository;
            ctx.FactoryMethodForService           = new Func <object>(() => serviceCreator());
            ctx.CreationMethod                    = EntityCreationType.Factory;
            ctx.ActionContextType                 = typeof(ActionContext <T>);

            if (repoCreator != null)
            {
                ctx.FactoryMethodForRepository = new Func <object>(() => repoCreator());
            }
            if (validatorCreator != null)
            {
                ctx.FactoryMethodForValidator = new Func <object>(() => validatorCreator());
            }

            EntityRegistration.Register(ctx);
        }