Esempio n. 1
0
        public MvcMiddleware(RequestDelegate next, HttpComponent httpComponent)
        {
            _next = next;

            _dispatcher = new Dictionary <string, IHttpHandler>();

            Type[] types = DllHelper.GetMonoTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(HttpHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
                if (!httpHandlerAttribute.AppType.Is(httpComponent.appType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IHttpHandler ihttpHandler = obj as IHttpHandler;
                if (ihttpHandler == null)
                {
                    throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
                }

                //this.dispatcher.Add(httpHandlerAttribute.Path, ihttpHandler);
                LoadMethod(type, httpHandlerAttribute, ihttpHandler);
            }
        }
Esempio n. 2
0
 public static void UseMvc(this HttpComponent self)
 {
     self.Use <MvcMiddleware>();
 }