예제 #1
0
 /// <summary>
 /// Initialize entity controller.
 /// </summary>
 /// <param name="builder">Context builder of entity.</param>
 public EntityController(IEntityContextBuilder builder)
     : base(builder)
 {
     EntityQueryable = EntityContext = EntityBuilder.GetContext <TEntity>();
     Metadata        = EntityAnalyzer.GetMetadata <TEntity>();
     PageSize        = Pagination.DefaultPageSizeOption;
     Untils          = new EntityControllerUnitils <TEntity>(this, builder);
     Untils.PageSize = PageSize;
 }
        /// <summary>
        /// Get untitils for controller.
        /// </summary>
        /// <typeparam name="T">Type of entity.</typeparam>
        /// <param name="controller">Controller.</param>
        /// <returns></returns>
        public static EntityControllerUnitils <T> GetUntitils <T>(this Controller controller) where T : class, IEntity, new()
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            object unitils;

            if (!controller.TempData.TryGetValue("controllerUntitils", out unitils))
            {
                var builder = controller.Resolver.GetService <IEntityContextBuilder>();
                if (builder == null)
                {
                    throw new NotSupportedException("Can not resolve IEntityContextBuilder.");
                }
                unitils = new EntityControllerUnitils <T>(controller, builder);
                controller.TempData.Add("controllerUntitils", unitils);
            }
            return((EntityControllerUnitils <T>)unitils);
        }