开发者

OpenRasta Framework for component (or composite) based web application

we are trying to build a more loosely coupled composite based web application, and looking at various options and frameworks.

The idea is like when the user browse to a page, the uri will be resolved on the server for a resource and a list of actions to take based on the configuration.

The view will be composed by some html markups and some components that are based on other URIs for their contents. The components are reusable and should not have any ideas about each other (maybe the context).

this is just an idea, and wanna see how the OpenRasta framework would help on this. I might be completely wrong with the approach; maybe this can be easily done with current as开发者_如何学Gop.net webform and mvc framework, but i would like to see your opinion.


I have just completed an OpenRasta site that relies on standard webcontrols that I inject into my views, passing on the strongly typed Resource (supplied by OR via the handler) to enable the control to surface resource properties etc in the usual way.

The resource instance carries the path to the control to be loaded and injected (Resource.ControlPath). This is set in the handler by concatenating aspects of the URI to find the control. This allows different URIs to request different versions of the same control that live at different locations in the site file hierarchy.

So, for example, ClientA requires an intro view with lots of client-specific text and features. ClientB also requires an intro page with different content and features.

This give two URIs

  • /myapp/clienta/intro
  • /myapp/clientb/intro

Configuration

ResourceSpace.Has.ResourcesOfType<IntroResource>()
        .AtUri("/myapp/{client}/intro")
        .HandledBy<IntroHandler>()
        .RenderedByAspx("~/Views/IntroView.aspx");

IntroHandler.cs

public class IntroHandler
{
    public OperationResult Get(string client)
    {
        var controlPath = ClientService.GetIntroControlPath(client);
        if (controlPath.IsEmpty()) return new OperationResult.NotFound();
        return new OperationResult.OK{
             ResponseResource = new IntroResource{
                              ControlPath = controlPath,
                              Client=client
                            }
          };
        }
    }
}

Intro.aspx

<%@ Page Language="C#" Inherits="OpenRasta.Codecs.WebForms.ResourceView<xx.IntroResource>" MasterPageFile="~/Views/View.Master" %>

<asp:Content ContentPlaceHolderID="head" ID="head" runat="server">
    <link href="/assets/CSS/intro.css" rel="stylesheet" type="text/css" />
    <%
        var userControl = Page.LoadControl(Resource.ControlPath) as UserControl;
        if (userControl == null) return;

        var property = userControl.GetType().GetProperty("Resource");
        if (property == null) return;

        property.SetValue(userControl, Resource, null);
        IntroContentControlHolder.Controls.Add(userControl);
    %>
</asp:Content>
<asp:Content ContentPlaceHolderID="body" ID="content" runat="server">
    <asp:placeholder runat="server" id="IntroContentControlHolder"></asp:placeholder>
</asp:Content>

Intro.ascx

<%@ Control CodeBehind="intro.ascx.cs" Language="C#" Inherits="xxxx.intro"%>

 <h1>Welcome <%=Resource.Client%></h1> 

...Lots more UI stuff

Intro.ascx.cs

public class intro : UserControl
{
    public IntroResource Resource { get; set; }
}

Therefore each version of the intro control extends the View with client specific features.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜