Esempio n. 1
0
        public static ImpressionEngine Create(string templatePath, IPropertyBag bag, ITemplateCache templateCache)
        {
            // create container and register it, in itself
            IContainer container = new Container();

            container.Register <IContainer>(delegate { return(container); });

            // singleton objects, only create once
            IReflector    reflector    = null;
            IFilterRunner filterRunner = null;
            ITagFactory   tagFactory   = null;

            container.Register <ITemplateCache>(delegate { return(templateCache); });
            container.Register <IReflector>(delegate { if (reflector == null)
                                                       {
                                                           reflector = new Reflector();
                                                       }
                                                       return(reflector); });
            container.Register <IFilterRunner>(delegate { if (filterRunner == null)
                                                          {
                                                              filterRunner = new FilterRunner();
                                                          }
                                                          return(filterRunner); });
            container.Register <ITagFactory>(delegate { if (tagFactory == null)
                                                        {
                                                            tagFactory = container.Resolve <TagFactory>();
                                                        }
                                                        return(tagFactory); });

            // instance scoped, create new each time
            container.Register <ITemplateParser, TemplateParser>();

            ImpressionEngine ie = container.Resolve <ImpressionEngine>();

            if (!string.IsNullOrEmpty(templatePath))
            {
                ie.LoadTemplate(templatePath, true);
            }

            if (bag != null)
            {
                ie.LoadBag(bag);
            }

            return(ie);
        }
Esempio n. 2
0
        public static ImpressionEngine Create(string templatePath, IPropertyBag bag, ITemplateCache templateCache)
        {
            // create container and register it, in itself
            IContainer container = new Container();
            container.Register<IContainer>(delegate { return container; });

            // singleton objects, only create once
            IReflector reflector = null;
            IFilterRunner filterRunner = null;
            ITagFactory tagFactory = null;

            container.Register<ITemplateCache>(delegate { return templateCache; });
            container.Register<IReflector>( delegate { if (reflector == null) reflector = new Reflector(); return reflector; } );
            container.Register<IFilterRunner>(delegate { if (filterRunner == null) filterRunner = new FilterRunner(); return filterRunner; });
            container.Register<ITagFactory>(delegate { if (tagFactory == null) tagFactory = container.Resolve<TagFactory>(); return tagFactory; });

            // instance scoped, create new each time
            container.Register<ITemplateParser, TemplateParser>();

            ImpressionEngine ie = container.Resolve<ImpressionEngine>();
            if (!string.IsNullOrEmpty(templatePath)) {
                ie.LoadTemplate(templatePath, true);
            }

            if (bag != null) {
                ie.LoadBag(bag);
            }

            return ie;
        }