Metadata >> Default >> Castle >> 1.0-RC3 >> Debug All >> Castle.MonoRail.Framework

Castle.MonoRail.Framework/Services/DefaultViewComponentFactory.cs

// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.Framework.Services
{
	using System;
	using System.Reflection;
	using Castle.Core.Logging;
	using Castle.MonoRail.Framework.Configuration;

	/// <summary>
	/// Default implementation of <see cref="IViewComponentFactory"/>
	/// <para>
	/// This implementation looks for concrete types that extend 
	/// <see cref="ViewComponent"/> in an assembly
	/// </para>
	/// </summary>
	public class DefaultViewComponentFactory : AbstractViewComponentFactory
	{
		/// <summary>
		/// The logger instance
		/// </summary>
		private ILogger logger = NullLogger.Instance;
		
		/// <summary>
		/// View engine instance used to initialize the <see cref="ViewComponent"/>
		/// instance upon creation
		/// </summary>
		private IViewEngine viewEngine;

		private String[] assemblies;

		/// <summary>
		/// A dictionary of name to ViewComponent
		/// </summary>
		private IViewComponentRegistry registry;

		/// <summary>
		/// Constructs a <c>DefaultViewComponentFactory</c>
		/// </summary>
		public DefaultViewComponentFactory()
		{
			registry = new DefaultViewComponentRegistry();
		}
		
		#region IInitializable implementation
		
		/// <summary>
		/// Invoked by the framework in order to initialize the state
		/// </summary>
		public override void Initialize()
		{
			base.Initialize();
			
			if (assemblies != null)
			{
				foreach(String assembly in assemblies)
				{
					Inspect(assembly);
				}
			}
			
			assemblies = null;
		}
		
		#endregion

		/// <summary>
		/// Gets the view component registry.
		/// </summary>
		/// <returns></returns>
		protected override IViewComponentRegistry GetViewComponentRegistry()
		{
			return registry;
		}

		/// <summary>
		/// Invoked by the framework in order to give a chance to
		/// obtain other services
		/// </summary>
		/// <param name="provider">The service proviver</param>
		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;
				}
			}
		}

		/// <summary>
		/// Loads the assembly and inspect its public types.
		/// </summary>
		/// <param name="assemblyFileName"></param>
		public void Inspect(String assemblyFileName)
		{
			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Inspecting assembly {0}", assemblyFileName);
			}
			
			Assembly assembly = Assembly.Load(assemblyFileName);
			
			Inspect(assembly);
		}

		/// <summary>
		/// Inspect the assembly's public types.
		/// </summary>
		public void Inspect(Assembly assembly)
		{
			Type[] types = assembly.GetExportedTypes();

			foreach(Type type in types)
			{
				if (!type.IsPublic || type.IsAbstract || type.IsInterface || type.IsValueType)
				{
					continue;
				}

				if (typeof(ViewComponent).IsAssignableFrom(type))
				{
					RegisterComponent(type.Name, type);
				}
			}
		}

		/// <summary>
		/// Implementors should return a reference to
		/// the current view engine.
		/// </summary>
		/// <value></value>
		public override IViewEngine ViewEngine
		{
			get { return viewEngine; }
			set { viewEngine = value; }
		}
	}
}

Castle.MonoRail.Framework

Depedencies

Name AssemblyVersion Culture PublicKeyToken Type
Castle.Components.Binder 1.0.3.0 neutral 407dd0808d44fbdc Required
Castle.Components.Common.EmailSender 1.0.3.0 neutral 407dd0808d44fbdc Required
Castle.Components.Validator 1.0.3.0 neutral 407dd0808d44fbdc Required
Castle.Core 1.0.3.0 neutral 407dd0808d44fbdc Required
mscorlib 2.0.0.0 neutral b77a5c561934e089 Required
System 2.0.0.0 neutral b77a5c561934e089 Required
System.Configuration 2.0.0.0 neutral b03f5f7f11d50a3a Required
System.Data 2.0.0.0 neutral b77a5c561934e089 Required
System.Design 2.0.0.0 neutral b03f5f7f11d50a3a Required
System.Drawing 2.0.0.0 neutral b03f5f7f11d50a3a Required
System.Web 2.0.0.0 neutral b03f5f7f11d50a3a Required
System.Windows.Forms 2.0.0.0 neutral b77a5c561934e089 Required
System.Xml 2.0.0.0 neutral b77a5c561934e089 Required

Sources

Path Related
Castle.MonoRail.Framework/Adapters/DefaultRailsEngineContext.cs Source
Castle.MonoRail.Framework/Adapters/FileDictionaryAdapter.cs Source
Castle.MonoRail.Framework/Adapters/RequestAdapter.cs Source
Castle.MonoRail.Framework/Adapters/ResponseAdapter.cs Source
Castle.MonoRail.Framework/Adapters/ServerUtilityAdapter.cs Source
Castle.MonoRail.Framework/Adapters/SessionAdapter.cs Source
Castle.MonoRail.Framework/Adapters/TraceAdapter.cs Source
Castle.MonoRail.Framework/Attributes/AccessibleThroughAttribute.cs Source
Castle.MonoRail.Framework/Attributes/AjaxActionAttribute.cs Source
Castle.MonoRail.Framework/Attributes/CacheAttribute.cs Source
Castle.MonoRail.Framework/Attributes/ControllerDetailsAttribute.cs Source
Castle.MonoRail.Framework/Attributes/DataBindAttribute.cs Source
Castle.MonoRail.Framework/Attributes/DefaultActionAttribute.cs Source
Castle.MonoRail.Framework/Attributes/DynamicActionProviderAttribute.cs Source
Castle.MonoRail.Framework/Attributes/FilterAttribute.cs Source
Castle.MonoRail.Framework/Attributes/HelperAttribute.cs Source
Castle.MonoRail.Framework/Attributes/LayoutAttribute.cs Source
Castle.MonoRail.Framework/Attributes/LocalizationFilterAttribute.cs Source
Castle.MonoRail.Framework/Attributes/PersistFlashAttribute.cs Source
Castle.MonoRail.Framework/Attributes/RescueAttribute.cs Source
Castle.MonoRail.Framework/Attributes/ResourceAttribute.cs Source
Castle.MonoRail.Framework/Attributes/ScaffoldingAttribute.cs Source
Castle.MonoRail.Framework/Attributes/SkipFilterAttribute.cs Source
Castle.MonoRail.Framework/Attributes/TransformFilterAttribute.cs Source
Castle.MonoRail.Framework/Attributes/ViewComponentDetailsAttribute.cs Source
Castle.MonoRail.Framework/Attributes/ViewComponentParamAttribute.cs Source
Castle.MonoRail.Framework/Configuration/ControllersConfig.cs Source
Castle.MonoRail.Framework/Configuration/DefaultUrl.cs Source
Castle.MonoRail.Framework/Configuration/DefaultUrlCollection.cs Source
Castle.MonoRail.Framework/Configuration/ExtensionEntry.cs Source
Castle.MonoRail.Framework/Configuration/ExtensionEntryCollection.cs Source
Castle.MonoRail.Framework/Configuration/MonoRailConfiguration.cs Source
Castle.MonoRail.Framework/Configuration/MonoRailSectionHandler.cs Source
Castle.MonoRail.Framework/Configuration/RoutingRule.cs Source
Castle.MonoRail.Framework/Configuration/RoutingRuleCollection.cs Source
Castle.MonoRail.Framework/Configuration/ScaffoldConfig.cs Source
Castle.MonoRail.Framework/Configuration/ServiceEntry.cs Source
Castle.MonoRail.Framework/Configuration/ServiceEntryCollection.cs Source
Castle.MonoRail.Framework/Configuration/SmtpConfig.cs Source
Castle.MonoRail.Framework/Configuration/TypeLoadUtil.cs Source
Castle.MonoRail.Framework/Configuration/ViewComponentsConfig.cs Source
Castle.MonoRail.Framework/Configuration/ViewEngineConfig.cs Source
Castle.MonoRail.Framework/Constants.cs Source
Castle.MonoRail.Framework/Controller.cs Source
Castle.MonoRail.Framework/ControllerException.cs Source
Castle.MonoRail.Framework/ControllerLifecycleExecutor.cs Source
Castle.MonoRail.Framework/ControllerNotFoundException.cs Source
Castle.MonoRail.Framework/Controllers/FilesController.cs Source
Castle.MonoRail.Framework/DelegateDynamicAction.cs Source
Castle.MonoRail.Framework/EngineContextModule.cs Source
Castle.MonoRail.Framework/Extensions/ExceptionChaining/AbstractExceptionHandler.cs Source
Castle.MonoRail.Framework/Extensions/ExceptionChaining/EmailHandler.cs Source
Castle.MonoRail.Framework/Extensions/ExceptionChaining/ExceptionChainingExtension.cs Source
Castle.MonoRail.Framework/Extensions/ExceptionChaining/FilteredExceptionHandler.cs Source
Castle.MonoRail.Framework/Extensions/ExceptionChaining/LoggingExceptionHandler.cs Source
Castle.MonoRail.Framework/Extensions/ExtensionManager.cs Source
Castle.MonoRail.Framework/Extensions/Session/CustomSessionExtension.cs Source
Castle.MonoRail.Framework/Filter.cs Source
Castle.MonoRail.Framework/Filters/AntiGoogleWebAcceleratorFilter.cs Source
Castle.MonoRail.Framework/Filters/LocalizationFilter.cs Source
Castle.MonoRail.Framework/Filters/PersistFlashFilter.cs Source
Castle.MonoRail.Framework/Filters/RequestValidatorFilter.cs Source
Castle.MonoRail.Framework/Flash.cs Source
Castle.MonoRail.Framework/Helpers/AbstractHelper.cs Source
Castle.MonoRail.Framework/Helpers/AjaxHelper.cs Source
Castle.MonoRail.Framework/Helpers/BehaviourHelper.cs Source
Castle.MonoRail.Framework/Helpers/DateFormatHelper.cs Source
Castle.MonoRail.Framework/Helpers/DictHelper.cs Source
Castle.MonoRail.Framework/Helpers/Effects2Helper.cs Source
Castle.MonoRail.Framework/Helpers/EffectsFatHelper.cs Source
Castle.MonoRail.Framework/Helpers/FormHelper.cs Source
Castle.MonoRail.Framework/Helpers/HtmlHelper.cs Source
Castle.MonoRail.Framework/Helpers/PaginationHelper.cs Source
Castle.MonoRail.Framework/Helpers/PrototypeHelper.cs Source
Castle.MonoRail.Framework/Helpers/ScriptaculousHelper.cs Source
Castle.MonoRail.Framework/Helpers/SetOperation.cs Source
Castle.MonoRail.Framework/Helpers/TextHelper.cs Source
Castle.MonoRail.Framework/Helpers/UrlHelper.cs Source
Castle.MonoRail.Framework/Helpers/ValidationHelper.cs Source
Castle.MonoRail.Framework/Helpers/ValidationStrategy/FValidateValidator.cs Source
Castle.MonoRail.Framework/Helpers/ValidationStrategy/PrototypeWebValidator.cs Source
Castle.MonoRail.Framework/Helpers/ValidationStrategy/ZebdaWebValidator.cs Source
Castle.MonoRail.Framework/Helpers/WizardHelper.cs Source
Castle.MonoRail.Framework/Helpers/ZebdaHelper.cs Source
Castle.MonoRail.Framework/Internal/ActionProviderUtil.cs Source
Castle.MonoRail.Framework/Internal/AssemblySourceInfo.cs Source
Castle.MonoRail.Framework/Internal/CommonUtils.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/ActionMetaDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/BaseMetaDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/ControllerDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/ControllerMetaDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/FilterDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/HelperDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/LayoutDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/RescueDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/ResourceDescriptor.cs Source
Castle.MonoRail.Framework/Internal/Descriptors/TransformFilterDescriptor.cs Source
Castle.MonoRail.Framework/Internal/JSCollectionGeneratorBase.cs Source
Castle.MonoRail.Framework/Internal/JSElementGeneratorBase.cs Source
Castle.MonoRail.Framework/Internal/JSGeneratorBase.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultFilterDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultHelperDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultLayoutDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultRescueDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultResourceDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/Providers/DefaultTransformFilterDescriptorProvider.cs Source
Castle.MonoRail.Framework/Internal/ResourceDictionary.cs Source
Castle.MonoRail.Framework/Internal/ResourceFacade.cs Source
Castle.MonoRail.Framework/Internal/ScaffoldException.cs Source
Castle.MonoRail.Framework/Internal/Test/TestContextHolder.cs Source
Castle.MonoRail.Framework/Internal/UrlInfo.cs Source
Castle.MonoRail.Framework/Internal/UrlTokenizerException.cs Source
Castle.MonoRail.Framework/Internal/ViewEngineInfo.cs Source
Castle.MonoRail.Framework/Internal/WizardUtils.cs Source
Castle.MonoRail.Framework/MonoRailHttpHandler.cs Source
Castle.MonoRail.Framework/MonoRailHttpHandlerFactory.cs Source
Castle.MonoRail.Framework/MonoRailServiceContainer.cs Source
Castle.MonoRail.Framework/ProcessEngine.cs Source
Castle.MonoRail.Framework/RailsException.cs Source
Castle.MonoRail.Framework/RoutingModule.cs Source
Castle.MonoRail.Framework/ServiceContainerAccessor.cs Source
Castle.MonoRail.Framework/ServiceProviderLocator.cs Source
Castle.MonoRail.Framework/Services/AbstractControllerFactory.cs Source
Castle.MonoRail.Framework/Services/AbstractServiceContainer.cs Source
Castle.MonoRail.Framework/Services/AbstractViewComponentFactory.cs Source
Castle.MonoRail.Framework/Services/AjaxProxyGenerator/PrototypeAjaxProxyGenerator.cs Source
Castle.MonoRail.Framework/Services/DefaultCacheProvider.cs Source
Castle.MonoRail.Framework/Services/DefaultControllerDescriptorProvider.cs Source
Castle.MonoRail.Framework/Services/DefaultControllerFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultControllerLifecycleExecutorFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultControllerTree.cs Source
Castle.MonoRail.Framework/Services/DefaultFilterFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultResourceFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultTransformFilterFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultUrlBuilder.cs Source
Castle.MonoRail.Framework/Services/DefaultUrlTokenizer.cs Source
Castle.MonoRail.Framework/Services/DefaultViewComponentFactory.cs Source
Castle.MonoRail.Framework/Services/DefaultViewComponentRegistry.cs Source
Castle.MonoRail.Framework/Services/DefaultViewEngineManager.cs Source
Castle.MonoRail.Framework/Services/EmailTemplateService.cs Source
Castle.MonoRail.Framework/Services/MonoRailSmtpSender.cs Source
Castle.MonoRail.Framework/Services/Utils/ControllerInspectionUtil.cs Source
Castle.MonoRail.Framework/Services/WeakReferenceCacheProvider.cs Source
Castle.MonoRail.Framework/SmartDispatcherController.cs Source
Castle.MonoRail.Framework/Test/MockCacheProvider.cs Source
Castle.MonoRail.Framework/Test/MockEmailTemplateService.cs Source
Castle.MonoRail.Framework/Test/MockRailsEngineContext.cs Source
Castle.MonoRail.Framework/Test/MockRequest.cs Source
Castle.MonoRail.Framework/Test/MockResponse.cs Source
Castle.MonoRail.Framework/Test/MockScaffoldingSupport.cs Source
Castle.MonoRail.Framework/Test/MockServerUtility.cs Source
Castle.MonoRail.Framework/Test/MockSmtpSender.cs Source
Castle.MonoRail.Framework/Test/MockTrace.cs Source
Castle.MonoRail.Framework/Test/MockViewComponentContext.cs Source
Castle.MonoRail.Framework/Test/MockViewEngine.cs Source
Castle.MonoRail.Framework/TransformFilter.cs Source
Castle.MonoRail.Framework/TransformFilters/Formatters/WikiFormatter.cs Source
Castle.MonoRail.Framework/TransformFilters/LowerCaseTransformFilter.cs Source
Castle.MonoRail.Framework/TransformFilters/UpperCaseTransformFilter.cs Source
Castle.MonoRail.Framework/TransformFilters/WikiTransformFilter.cs Source
Castle.MonoRail.Framework/ViewComponent.cs Source
Castle.MonoRail.Framework/ViewComponentException.cs Source
Castle.MonoRail.Framework/ViewComponents/AuthenticatedContent.cs Source
Castle.MonoRail.Framework/ViewComponents/CaptureFor.cs Source
Castle.MonoRail.Framework/ViewComponents/ChildContentComponent.cs Source
Castle.MonoRail.Framework/ViewComponents/ColumnRenderer.cs Source
Castle.MonoRail.Framework/ViewComponents/DiggStylePagination.cs Source
Castle.MonoRail.Framework/ViewComponents/SecurityComponent.cs Source
Castle.MonoRail.Framework/ViewComponents/UpdatePage.cs Source
Castle.MonoRail.Framework/ViewComponents/UpdatePageTag.cs Source
Castle.MonoRail.Framework/Views/Aspx/Contents.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/AbstractBindingComponent.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/AbstractBindingScope.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/AbstractEventScope.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionArgument.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionArgumentCollection.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionBinding.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionBindingCollection.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionBindingTypeConverter.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ActionListConverter.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/BindableControlIDConverter.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/BindingContext.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/CommandBinding.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/CommandEventHandlerDelegate.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ControllerBinder.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ControllerBinding.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/ControllerBindingCollection.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/DataBindingEvaluator.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/ActionArgumentsEditor.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/ActionArgumentsEditorForm.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/ActionArgumentsEditorForm.designer.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/ActionArgumentsPropertyGridAdapter.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/ControllerActionBinderDesigner.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/DesignUtil.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/Design/StandardTarget.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/EventHandlerDelegate.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/EventHandlerFactory.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/EventListConverter.cs Source
Castle.MonoRail.Framework/Views/Aspx/ControllerBinder/TypedCollection.cs Source
Castle.MonoRail.Framework/Views/Aspx/EventUtil.cs Source
Castle.MonoRail.Framework/Views/Aspx/InvokeHelper.cs Source
Castle.MonoRail.Framework/Views/Aspx/MasterPageBase.cs Source
Castle.MonoRail.Framework/Views/Aspx/WebFormsViewEngine.cs Source
Castle.MonoRail.Framework/Views/Aspx/WebFormUtils.cs Source
Castle.MonoRail.Framework/Views/EmbeddedResourceViewSource.cs Source
Castle.MonoRail.Framework/Views/FileAssemblyViewSourceLoader.cs Source
Castle.MonoRail.Framework/Views/FileViewSource.cs Source
Castle.MonoRail.Framework/Views/ViewEngineBase.cs Source
Castle.MonoRail.Framework/WizardActionProvider.cs Source
Castle.MonoRail.Framework/WizardStepPage.cs Source