refactoring:
[mono.git] / mcs / class / Mainsoft.Web / Mainsoft.Web.Hosting / SessionWrapper.cs
index d66d5951052ecfe2da2031fa6e241ce6122bec1a..5af48a481237605400d63e3b9ba6d62c87be699b 100644 (file)
@@ -12,26 +12,19 @@ namespace Mainsoft.Web.Hosting
                static readonly Type IRequiresSessionStateType = typeof (IRequiresSessionState);\r
                static readonly Type IReadOnlySessionStateType = typeof (IReadOnlySessionState);\r
 \r
-               public static IHttpHandler WrapHandler (IHttpHandler handler, HttpContext context, string url) {\r
-                       Type type = PageMapper.GetObjectType (context, url);\r
+               public static IHttpHandler WrapHandler (IHttpHandler handler) {\r
+                       Type type = (Type) ((IServiceProvider) handler).GetService (typeof (Type));\r
 \r
                        if (IRequiresSessionStateType.IsAssignableFrom (type))\r
                                return IReadOnlySessionStateType.IsAssignableFrom (type) ?\r
-                                       new ReadOnlySessionWrapperHandler (handler) : new SessionWrapperHandler (handler);\r
-                       return handler;\r
-               }\r
-               public static IHttpHandler WrapHandler (IHttpExtendedHandler handler, HttpContext context, string url) {\r
-                       Type type = PageMapper.GetObjectType (context, url);\r
-\r
-                       if (IRequiresSessionStateType.IsAssignableFrom (type))\r
-                               return IReadOnlySessionStateType.IsAssignableFrom (type) ?\r
-                                       new ReadOnlySessionWrapperExtendedHandler (handler) : new SessionWrapperExtendedHandler (handler);\r
+                                       (handler is IHttpExtendedHandler ? (IHttpHandler) new ReadOnlySessionWrapperExtendedHandler ((IHttpExtendedHandler) handler) : new ReadOnlySessionWrapperHandler (handler)) :\r
+                                       (handler is IHttpExtendedHandler ? new SessionWrapperExtendedHandler ((IHttpExtendedHandler) handler) : new SessionWrapperHandler (handler));\r
                        return handler;\r
                }\r
 \r
                #region SessionWrappers\r
 \r
-               class SessionWrapperHandler : IHttpHandler, IRequiresSessionState\r
+               class SessionWrapperHandler : IHttpHandler, IRequiresSessionState, IServiceProvider\r
                {\r
                        protected readonly IHttpHandler _handler;\r
 \r
@@ -46,6 +39,10 @@ namespace Mainsoft.Web.Hosting
                        public void ProcessRequest (HttpContext context) {\r
                                _handler.ProcessRequest (context);\r
                        }\r
+\r
+                       public object GetService (Type serviceType) {\r
+                               return ((IServiceProvider) _handler).GetService (serviceType);\r
+                       }\r
                }\r
 \r
                sealed class ReadOnlySessionWrapperHandler : SessionWrapperHandler, IReadOnlySessionState\r
@@ -66,14 +63,6 @@ namespace Mainsoft.Web.Hosting
                        public bool IsCompleted {\r
                                get { return ((IHttpExtendedHandler) _handler).IsCompleted; }\r
                        }\r
-\r
-                       public object GetContextState (HttpContext context) {\r
-                               return ((IHttpExtendedHandler) _handler).GetContextState (context);\r
-                       }\r
-\r
-                       public void SetContextState (HttpContext context, object state) {\r
-                               ((IHttpExtendedHandler) _handler).SetContextState (context, state);\r
-                       }\r
                }\r
 \r
                sealed class ReadOnlySessionWrapperExtendedHandler : SessionWrapperExtendedHandler, IReadOnlySessionState\r