Castle.MonoRail.Framework.Services.DefaultViewComponentFactory.Service C# (CSharp) Method

Service() public method

Invoked by the framework in order to give a chance to obtain other services
public Service ( IServiceProvider provider ) : void
provider IServiceProvider The service proviver
return void
		public override void Service(IServiceProvider provider)
		{
			base.Service(provider);
			
			ILoggerFactory loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory));
			
			if (loggerFactory != null)
			{
				logger = loggerFactory.Create(typeof(DefaultViewComponentFactory));
			}

			MonoRailConfiguration config = (MonoRailConfiguration) provider.GetService(typeof(MonoRailConfiguration));
			
			if (config != null)
			{
				assemblies = config.ViewComponentsConfig.Assemblies;
				
				if (assemblies == null || assemblies.Length == 0)
				{
					// Convetion: uses the controller assemblies in this case
					
					assemblies = config.ControllersConfig.Assemblies;
				}
			}
		}

Usage Example

Example #1
0
        public virtual void SetUp()
        {

            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers = new HelperDictionary();
            var services = new StubMonoRailServices
                               {
                                   UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()),
                                   UrlTokenizer = new DefaultUrlTokenizer()
                               };
            var urlInfo = new UrlInfo(
                "example.org", "test", "/TestBrail", "http", 80,
                "http://test.example.org/test_area/test_controller/test_action.tdd",
                Area, ControllerName, Action, "tdd", "no.idea");
            StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services, urlInfo);
            StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
            StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);

            ViewComponentFactory = new DefaultViewComponentFactory();
            ViewComponentFactory.Service(StubEngineContext);
            ViewComponentFactory.Initialize();

            StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
            ControllerContext = new ControllerContext
                                    {
                                        Helpers = Helpers, 
                                        PropertyBag = PropertyBag
                                    };
            StubEngineContext.CurrentControllerContext = ControllerContext;


            Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext);
            Helpers["formhelper"] = Helpers["form"] = new FormHelper(StubEngineContext);
            Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext);
            Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext);



            var loader = new FileAssemblyViewSourceLoader("Views");
            _monoRailViewEngine = new NHamlMonoRailViewEngine();
            _monoRailViewEngine.TemplateEngine.Options.TemplateCompiler = new CSharp3TemplateCompiler();
            _monoRailViewEngine.SetViewSourceLoader(loader);
            _templateEngine = _monoRailViewEngine.TemplateEngine;
            _templateEngine.Options.TemplateBaseType = typeof( NHamlMonoRailView );
            


            ViewComponentFactory.Inspect(GetType().Assembly);

        }
All Usage Examples Of Castle.MonoRail.Framework.Services.DefaultViewComponentFactory::Service