public void Register(Type type, ControllerAttribute ca, Action <EventActionRegistingArgs> callback = null) { try { EventControllerInstanceArgs e = new EventControllerInstanceArgs(); e.Type = type; OnControllerInstance(e); if (e.Controller == null) { Register(Server.Options, type, Activator.CreateInstance(type), ca.BaseUrl, Server, ca, callback); } else { Register(Server.Options, type, e.Controller, ca.BaseUrl, Server, ca, callback); } } catch (Exception e_) { if (Server.EnableLog(EventArgs.LogType.Error)) { string msg = $"{type} controller register error {e_.Message} {e_.StackTrace}"; Server.Log(EventArgs.LogType.Error, msg); } } }
public void Register(HttpConfig config, HttpApiServer server, params Assembly[] assemblies) { foreach (Assembly item in assemblies) { Type[] types = item.GetTypes(); foreach (Type type in types) { ControllerAttribute ca = type.GetCustomAttribute <ControllerAttribute>(false); if (ca != null) { EventControllerInstanceArgs e = new EventControllerInstanceArgs(); e.Type = type; OnControllerInstance(e); if (e.Controller == null) { Register(config, type, Activator.CreateInstance(type), ca.BaseUrl, server, ca); } else { Register(config, type, e.Controller, ca.BaseUrl, server, ca); } } } } }
public object GetController(Type type) { EventControllerInstanceArgs e = new EventControllerInstanceArgs(); e.Type = type; OnControllerInstance(e); return(e.Controller); }
public object GetController(Type type, IHttpContext context) { EventControllerInstanceArgs e = new EventControllerInstanceArgs(); e.Type = type; e.Context = context; OnControllerInstance(e); return(e.Controller); }
public void Register(params Assembly[] assemblies) { AssembliesLoading?.Invoke(assemblies); foreach (Assembly item in assemblies) { Type[] types = item.GetTypes(); foreach (Type type in types) { PMapper mapper = type.GetCustomAttribute <PMapper>(false); if (mapper != null) { RegisterParameterBinder(mapper.ParameterType, type); } } } foreach (Assembly item in assemblies) { Type[] types = item.GetTypes(); foreach (Type type in types) { ControllerAttribute ca = type.GetCustomAttribute <ControllerAttribute>(false); if (ca != null) { try { EventControllerInstanceArgs e = new EventControllerInstanceArgs(); e.Type = type; OnControllerInstance(e); if (e.Controller == null) { Register(Server.Options, type, Activator.CreateInstance(type), ca.BaseUrl, Server, ca, null); } else { Register(Server.Options, type, e.Controller, ca.BaseUrl, Server, ca, null); } } catch (Exception e_) { if (Server.EnableLog(EventArgs.LogType.Error)) { string msg = $"{type} controller register error {e_.Message} {e_.StackTrace}"; Server.Log(EventArgs.LogType.Error, msg); } } } } } }
protected virtual void OnControllerInstance(EventControllerInstanceArgs e) { ControllerInstance?.Invoke(this, e); }