I am working on a composite runtime resource library for ASP.NET WebForms / MVC. I support both standard ASP.NET WebForms through WebControls, and recently added support for ASP MVC Html Helpers. One of the features that I currently support with WebForms WebControls is the concept of "partial" resource definitions, where the resource can be combined through the Wizard / View pages, etc.
When implementing the MVC equivalent, I'm not sure what is the best practice? Currently, I'm leaning toward design something like this:
Master page
<% using (Html.CreateCompositeResourcePartContext()) { Html.CompositeCssResourcePart( "ResourceName", new[] { "/Styles/SharedStyle1.css", "/Styles/SharedStyle2.css" } ); %> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> <% } %>
Which will create a “contextual” wrapper around the head of the ContentPlaceholder.
View page
<asp:Content ID="HeadContentPlaceholder" ContentPlaceHolderID="head" runat="server"> <% Html.CompositeCssResourcePart( "ResourceName", new[] { "/Styles/PageStyle5.css", "/Styles/PageStyle6.css", "/Styles/PageStyle7.css" }) %> </asp:Content>
In this way, any browsing pages can extend the definition of a partial resource, as shown above.
The questions I have are:
1) Unlike all other HtmlHelpers, these extensions do not immediately write out an HTML fragment, but rather wait until the context is deleted. Should these extensions be disconnected from the ViewContext (or another object)?
2) I personally think that the concept of “use” makes sense to wrap a block of code rather than separate calls to BeginCompositeResourcePartContext / EndCompositeResourcePartContext, do you agree? If not, what is better about individual method calls?
Any feedback on the above issue would be greatly appreciated. If more information is required, please let me know.
Edit
To clarify ... the block inside the chapter of the main page and the subsequent link on the side of the view page will be combined together into one resource. Therefore, when the CompositeResourcePartContext context is placed, all SIX files are combined into only one css file and written out as a single TAG link (or script, css sprite, etc.)
<link rel="stylesheet" type="text/css" href="/MyMergedStyleSheet.css" />