예제 #1
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);
        }
예제 #2
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);
        }