1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Services
17 using System
.Collections
.Generic
;
25 public class DefaultControllerContextFactory
: IControllerContextFactory
30 /// <param name="area"></param>
31 /// <param name="controller"></param>
32 /// <param name="action"></param>
33 /// <param name="metaDescriptor"></param>
34 /// <returns></returns>
35 public IControllerContext
Create(string area
, string controller
, string action
,
36 ControllerMetaDescriptor metaDescriptor
)
38 return Create(area
, controller
, action
, metaDescriptor
, new RouteMatch());
44 /// <param name="area">The area.</param>
45 /// <param name="controller">The controller.</param>
46 /// <param name="action">The action.</param>
47 /// <param name="metaDescriptor">The meta descriptor.</param>
48 /// <param name="match">The routing match.</param>
49 /// <returns></returns>
50 public IControllerContext
Create(string area
, string controller
, string action
,
51 ControllerMetaDescriptor metaDescriptor
, RouteMatch match
)
53 ControllerContext context
= new ControllerContext(controller
, area
, action
, metaDescriptor
);
54 context
.RouteMatch
= match
;
55 context
.ViewFolder
= ResolveViewFolder(context
, area
, controller
, action
);
56 context
.SelectedViewName
= ResolveDefaultViewSelection(context
, area
, controller
, action
);
58 foreach(KeyValuePair
<string, string> pair
in match
.Parameters
)
60 if (pair
.Key
== "controller" || pair
.Key
== "action" || pair
.Key
== "area")
62 // We skip those only to avoid compatibility issues as
63 // customactionparameters have higher precedence on parameters matching
67 context
.CustomActionParameters
[pair
.Key
] = pair
.Value
;
76 /// <param name="context">The context.</param>
77 /// <param name="area">The area.</param>
78 /// <param name="controller">The controller.</param>
79 /// <param name="action">The action.</param>
80 /// <returns></returns>
81 protected virtual string ResolveViewFolder(ControllerContext context
, string area
, string controller
, string action
)
83 if (!string.IsNullOrEmpty(area
))
85 return Path
.Combine(area
, controller
);
94 /// <param name="context">The context.</param>
95 /// <param name="area">The area.</param>
96 /// <param name="controller">The controller.</param>
97 /// <param name="action">The action.</param>
98 /// <returns></returns>
99 protected virtual string ResolveDefaultViewSelection(ControllerContext context
, string area
, string controller
,
102 return Path
.Combine(context
.ViewFolder
, action
);