public static ClassWrapper.ClassWrapper GetWrapper(object model)
		{
			var type = model.GetType();
			if (!_classWrappers.ContainsKey(type))
			{
				if ((type.Namespace!=null && type.Namespace.StartsWith("System")) || type.IsValueType) return null;
				var clw = new ClassWrapperDescriptor(type);
				clw.Load();
				_classWrappers.AddOrUpdate(type, clw, (a, b) => b);
			}
			return _classWrappers[type].CreateWrapper(model);
		}
		public static void RegisterModelType(Type type)
		{
			if ((type.Namespace != null && type.Namespace.StartsWith("System")) || type.IsValueType) return;
			if (_classWrappers.ContainsKey(type)) return;
			if (typeof(NameValueCollection).IsAssignableFrom(type)) return;
			var cld = new ClassWrapperDescriptor(type);
			cld.Load();
			_classWrappers.TryAdd(type, cld);

			foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
			{
				RegisterModelType(property.PropertyType);
			}
		}
Beispiel #3
0
		private void CallClientInitializers()
		{
			var par = GetParameter<string>("authenticationType");
			if (!string.IsNullOrEmpty(par)) _securityDefinition.AuthenticationType = par;
			par = GetParameter<string>("realm");
			if (!string.IsNullOrEmpty(par)) _securityDefinition.Realm = par;
			par = GetParameter<string>("loginPage");
			if (!string.IsNullOrEmpty(par)) _securityDefinition.LoginPage = par;

			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<ILocatorInitialize>())
			{
				var initializer = (ILocatorInitialize)ServiceLocator.Locator.Resolve(type);
				initializer.InitializeLocator(ServiceLocator.Locator);
			}
			IAuthenticationDataProvider authenticationDataProvider = null;
			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<IAuthenticationDataProviderFactory>())
			{
				var initializer = (IAuthenticationDataProviderFactory)ServiceLocator.Locator.Resolve(type);
				authenticationDataProvider = initializer.CreateAuthenticationDataProvider();
				ServiceLocator.Locator.Register<IAuthenticationDataProvider>(authenticationDataProvider);
				break;
			}
			if (authenticationDataProvider == null)
			{
				ServiceLocator.Locator.Register<IAuthenticationDataProvider>(NullAuthenticationDataProvider.Instance);
			}
			ForceMemebershipProvider(ServiceLocator.Locator.Resolve<IAuthenticationDataProvider>());
			ISessionManager sessionManager = null;
			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<ISessionManagerFactory>())
			{
				var initializer = (ISessionManagerFactory)ServiceLocator.Locator.Resolve(type);
				sessionManager = initializer.CreateSessionManager();
				ServiceLocator.Locator.Register<ISessionManager>(sessionManager);
				break;
			}
			if (sessionManager == null)
			{
				ServiceLocator.Locator.Register<ISessionManager>(new BasicSessionManager());
			}
			var sessionCache = GetParameter<INodeModule>(HttpParameters.HttpSessionCache);
			if (sessionCache != null)
			{
				ServiceLocator.Locator.Resolve<ISessionManager>().SetCachingEngine(sessionCache.GetParameter<ICacheEngine>(HttpParameters.CacheInstance));

			}
			if (_routingHandler == null) return;
			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<IRouteInitializer>())
			{
				var initializer = (IRouteInitializer)ServiceLocator.Locator.Resolve(type);
				initializer.RegisterRoutes(_routingHandler);
			}
			var controllers = AssembliesManager.LoadTypesInheritingFrom<IController>().ToArray();
			_routingHandler.LoadControllers(controllers);
			foreach (var controller in controllers)
			{
				ServiceLocator.Locator.Register(controller);
				var cld = new ClassWrapperDescriptor(controller, true);
				cld.Load();
				foreach (var method in cld.Methods)
				{
					var methodGroup = cld.GetMethodGroup(method);
					foreach (var meth in methodGroup)
					{
						if (meth.Visibility != ItemVisibility.Public) continue;
						if (meth.Parameters.Count == 0) continue;
						foreach (var param in meth.Parameters)
						{
							var paramType = param.ParameterType;
							if (!paramType.IsValueType && paramType.Namespace != null && !paramType.Namespace.StartsWith("System"))
							{
								ValidationService.RegisterModelType(param.ParameterType);
							}
						}
					}
				}
				_controllers.Add(controller.Name, new ControllerWrapperDescriptor(cld));

			}
			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<IFiltersInitializer>())
			{
				var initializer = (IFiltersInitializer)ServiceLocator.Locator.Resolve(type);
				initializer.InitializeFilters(_filtersHandler);
			}
			var resourceBundler = new ResourceBundles(_virtualDir,_pathProviders);
			ServiceLocator.Locator.Register<IResourceBundles>(resourceBundler);
			foreach (var type in AssembliesManager.LoadTypesInheritingFrom<IResourceBundleInitializer>())
			{
				var initializer = (IResourceBundleInitializer)ServiceLocator.Locator.Resolve(type);
				initializer.RegisterBundles(resourceBundler);
			}
		}