The base class for the context loading an item from the CMS
Example #1
0
        public ConfigurationResolverArgs RunConfigurationPipeline(AbstractTypeCreationContext abstractTypeCreationContext)
        {
            var configurationArgs = new ConfigurationResolverArgs(GlassContext, abstractTypeCreationContext, abstractTypeCreationContext.RequestedType, this);

            configurationArgs.Parameters = abstractTypeCreationContext.Parameters;
            _configurationResolver.Run(configurationArgs);

            return(configurationArgs);
        }
Example #2
0
        /// <summary>
        /// Instantiates the object.
        /// </summary>
        /// <param name="abstractTypeCreationContext">The abstract type creation context.</param>
        /// <returns></returns>
        /// <exception cref="System.NullReferenceException">Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}.Formatted(abstractTypeCreationContext.RequestedType.FullName)</exception>
        public object InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
        {
            using (new Monitor())
            {
                string profilerKey = "Creating {0}".Formatted(abstractTypeCreationContext.Options.Type.FullName);

                try
                {
                    Profiler.IndentIncrease();
                    Profiler.Start(profilerKey);

                    if (this._disposed)
                    {
                        throw new MapperException("Service has been disposed, cannot create object");
                    }

                    //run the pipeline to get the configuration to load
                    var configurationArgs = RunConfigurationPipeline(abstractTypeCreationContext);
                    if (configurationArgs.Result == null)
                    {
                        throw new NullReferenceException(
                                  "Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}"
                                  .Formatted(abstractTypeCreationContext.Options.Type));
                    }

                    //Run the object construction
                    var objectArgs = new ObjectConstructionArgs(
                        GlassContext,
                        abstractTypeCreationContext,
                        configurationArgs.Result,
                        this
                        );

                    objectArgs.Parameters = configurationArgs.Parameters;


                    _objectConstruction.Run(objectArgs);
                    ModelCounter.Instance.ModelsRequested++;

                    return(objectArgs.Result);
                }

                finally
                {
                    //we clear the lazy loader disable to avoid problems with
                    //stack overflows on the next request
                    Profiler.End(profilerKey);
                    Profiler.IndentDecrease();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Instantiates the object.
        /// </summary>
        /// <param name="abstractTypeCreationContext">The abstract type creation context.</param>
        /// <returns></returns>
        /// <exception cref="System.NullReferenceException">Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}.Formatted(abstractTypeCreationContext.RequestedType.FullName)</exception>
        public object InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
        {
            //run the pipeline to get the configuration to load
            var configurationArgs = RunConfigurationPipeline(abstractTypeCreationContext);

            if (configurationArgs.Result == null)
            {
                throw new NullReferenceException("Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}".Formatted(abstractTypeCreationContext.RequestedType));
            }

            //Run the object construction
            var objectArgs = new ObjectConstructionArgs(GlassContext, abstractTypeCreationContext, configurationArgs.Result, this);

            objectArgs.Parameters = configurationArgs.Parameters;
            _objectConstruction.Run(objectArgs);

            return(objectArgs.Result);
        }
Example #4
0
 /// <summary>
 /// Used to create the context used by DataMappers to map data to a class
 /// </summary>
 /// <param name="creationContext"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 public abstract AbstractDataMappingContext CreateDataMappingContext(AbstractTypeCreationContext creationContext, object obj);
 /// <summary>
 /// Used to create the context used by DataMappers to map data to a class
 /// </summary>
 /// <param name="creationContext"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 public abstract AbstractDataMappingContext CreateDataMappingContext(AbstractTypeCreationContext creationContext, object obj);
        public ConfigurationResolverArgs RunConfigurationPipeline(AbstractTypeCreationContext abstractTypeCreationContext)
        {
            var configurationArgs = new ConfigurationResolverArgs(GlassContext, abstractTypeCreationContext, abstractTypeCreationContext.RequestedType, this);
            configurationArgs.Parameters = abstractTypeCreationContext.Parameters;
            _configurationResolver.Run(configurationArgs);

            return configurationArgs;
        }
        /// <summary>
        /// Instantiates the object.
        /// </summary>
        /// <param name="abstractTypeCreationContext">The abstract type creation context.</param>
        /// <returns></returns>
        /// <exception cref="System.NullReferenceException">Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}.Formatted(abstractTypeCreationContext.RequestedType.FullName)</exception>
        public object InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
        {
            //run the pipeline to get the configuration to load
            var configurationArgs = RunConfigurationPipeline(abstractTypeCreationContext);
            if (configurationArgs.Result == null)
                throw new NullReferenceException("Configuration Resolver pipeline did not return a type. Has the type been loaded by Glass.Mapper. Type: {0}".Formatted(abstractTypeCreationContext.RequestedType));
            
            //Run the object construction
            var objectArgs = new ObjectConstructionArgs(GlassContext, abstractTypeCreationContext, configurationArgs.Result, this);
            objectArgs.Parameters = configurationArgs.Parameters;
            _objectConstruction.Run(objectArgs);

            return objectArgs.Result;
        }