コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Initialize the service, repository creators.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceCreator">The service creator.</param>
        /// <param name="repoCreator">The repository creator.</param>
        /// <param name="validatorCreator">The validator creator.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="resources">The resources.</param>
        /// <param name="configureRepository">Whether or not to configure the reposiory.</param>
        /// <param name="connectionId">The connection id.</param>
        public static void Register <T>(Func <IEntityService <T> > serviceCreator, Func <IRepository <T> > repoCreator,
                                        Func <IEntityValidator> validatorCreator, IEntitySettings settings, IEntityResources resources, bool configureRepository, string connectionId)
        {
            EntityRegistrationContext ctx = new EntityRegistrationContext();

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

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

            EntityRegistration.Register(ctx);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Determines whether the specified type has validator.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>
        ///     <c>true</c> if the specified type has validator; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasValidator(Type type)
        {
            EntityRegistrationContext ctx = null;

            if (!_managableEntities.ContainsKey(type.FullName))
            {
                if (_managableEntities.ContainsKey(type.BaseType.FullName))
                {
                    ctx = _managableEntities[type.BaseType.FullName];
                }
            }
            else
            {
                ctx = _managableEntities[type.FullName];
            }

            if (ctx == null)
            {
                return(false);
            }
            if (ctx.FactoryMethodForValidator == null &&
                ctx.Validator == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        /// <summary>
        /// Get instance of entity validator.
        /// </summary>
        /// <param name="typeFullName">typeof(T).FullName</param>
        /// <returns></returns>
        public static object GetValidator(string typeFullName)
        {
            EntityRegistrationContext ctx = _managableEntities[typeFullName];

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

            return(ctx.Validator);
        }
コード例 #9
0
        /// <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));
        }
コード例 #10
0
        /// <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));
        }
コード例 #11
0
        /// <summary>
        /// Get instance of entity repository.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static object GetRepository(EntityRegistrationContext ctx)
        {
            IRepositoryConfigurable repo = null;

            // If factory method was supplied.
            if (ctx.FactoryMethodForRepository != null)
            {
                repo = ctx.FactoryMethodForRepository() as IRepositoryConfigurable;
                if (repo != null && ctx.IsRepositoryConfigurationRequired)
                {
                    RepositoryFactory.Configure(ctx.ConnectionId, repo);
                }

                return(repo);
            }

            return(ctx.Repository);
        }
コード例 #12
0
 /// <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);
     }
 }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        /// <summary>
        /// Get the entity Service(supporting CRUD operations).
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public static object GetService(string typeFullName)
        {
            if (!_managableEntities.ContainsKey(typeFullName))
            {
                throw new ArgumentException("The type : " + typeFullName + " has not been registered in EntityRegistration");
            }

            EntityRegistrationContext ctx = _managableEntities[typeFullName];

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

            object service = null;

            if (ctx.CreationMethod == EntityCreationType.Factory)
            {
                service = ctx.FactoryMethodForService();
                if (ctx.FactoryMethodForRepository != null)
                {
                    var repository = GetRepository(ctx);
                    service.GetType().GetProperty("Repository").SetValue(service, repository, null);
                }
                if (ctx.FactoryMethodForValidator != null)
                {
                    var validator = GetValidator(typeFullName);
                    service.GetType().GetProperty("Validator").SetValue(service, validator, null);
                }
                if (ctx.Settings != null)
                {
                    service.GetType().GetProperty("Settings").SetValue(service, ctx.Settings, null);
                }

                return(service);
            }
            return(ctx.Service);
        }
コード例 #16
0
        /// <summary>
        /// Get instance of entity repository.
        /// </summary>
        /// <param name="typeFullName">typeof(T).FullName</param>
        /// <returns></returns>
        public static object GetRepository(string typeFullName)
        {
            if (!_managableEntities.ContainsKey(typeFullName))
            {
                throw new ArgumentException("The type : " + typeFullName + " has not been registered in EntityRegistration");
            }

            EntityRegistrationContext ctx  = _managableEntities[typeFullName];
            IRepositoryConfigurable   repo = null;

            // If factory method was supplied.
            if (ctx.FactoryMethodForRepository != null)
            {
                repo = ctx.FactoryMethodForRepository() as IRepositoryConfigurable;
                if (repo != null && ctx.IsRepositoryConfigurationRequired)
                {
                    RepositoryFactory.Configure(ctx.ConnectionId, repo);
                }

                return(repo);
            }

            return(ctx.Repository);
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        /// <summary>
        /// Get instance of entity settings.
        /// </summary>
        /// <param name="typeFullName">typeof(T).FullName</param>
        /// <returns></returns>
        public static object GetSettings(string typeFullName)
        {
            EntityRegistrationContext ctx = _managableEntities[typeFullName];

            return(ctx.Settings);
        }
コード例 #19
0
        /// <summary>
        /// Get instance of entity context.
        /// </summary>
        /// <param name="typeFullName">typeof(T).FullName</param>
        /// <returns></returns>
        public static IActionContext GetContext(string typeFullName)
        {
            EntityRegistrationContext ctx = _managableEntities[typeFullName];

            return(new ActionContext());
        }