public IController CreateController(RequestContext requestContext, string controllerName) { if (controllerName == "favico.ico") { return(null); } IController controller = null; Type controllerType = null; MyControllerXmlParser parser = new MyControllerXmlParser(); List <ControllerTypeInfo> types = parser.Parse(); ControllerTypeInfo ti = types.FirstOrDefault(t => t.Name == controllerName); if (ti == null) { throw new KeyNotFoundException(); } controllerType = Type.GetType(ti.Path); //Controller ITotoLogger logger = new DebuggerLogger(); //Logger controller = (IController)Activator.CreateInstance(controllerType, logger); return(controller); }
/// <summary> /// 获得某模块控制器. /// </summary> /// <returns> /// The controller. /// </returns> /// <param name='controllerType'> /// 模块类型. /// </param> public IController GetController(ControllerTypeInfo controllerType) { foreach (IController controller in iControllers) { if (controller.GetControllerType() == controllerType) { return(controller); } } return(null); }
/// <summary> /// 向网关注册服务 /// </summary> /// <param name="contollerType">Controller类型</param> /// <param name="serviceName">服务名称</param> public void Register(Type contollerType, string serviceName) { _services.AddTransient(contollerType); ServiceNames[serviceName] = new ControllerTypeInfo() { Type = contollerType, Enable = true, Methods = contollerType.GetTypeInfo().DeclaredMethods.Where(m => m.IsStatic == false && m.IsPublic && m.DeclaringType != typeof(MicroServiceControllerBase) && m.DeclaringType != typeof(object)).OrderBy(m => m.Name).ToArray() }; }
/// <summary> /// 向网关注册服务 /// </summary> /// <param name="contollerType">Controller类型</param> /// <param name="serviceName">服务名称</param> public void Register(Type contollerType, string serviceName) { _services.AddTransient(contollerType); ServiceNames[serviceName] = new ControllerTypeInfo() { Type = contollerType, Enable = true, NeedAuthorize = contollerType.GetCustomAttribute <AuthorizeAttribute>() != null, Methods = contollerType.GetTypeInfo().DeclaredMethods.Where(m => m.IsStatic == false && m.IsPublic && m.DeclaringType != typeof(MicroServiceControllerBase) && m.DeclaringType != typeof(object)).OrderBy(m => m.Name).Select(m => new TypeMethodInfo { Method = m, NeedAuthorize = m.GetCustomAttribute <AuthorizeAttribute>() != null }).ToArray() }; }