|
10:12 PM Monday Feb 23, 2009
Comments: 0
This is my attempt at curing a case of Analysis Paralysis that I've had for awhile.
I promised myself that I'd rebuild my blog by the end of Feb so here goes nothing. I've been procrastinating for awhile so I figured if I pulled the plug on the old software, I'd be more motivated to do the rewrite. I'll be slowly adding content back in and trying to come up with a good design.
8:32 AM Sunday Feb 22, 2009
Comments: 0
After updating to the latest Castle trunk and trying to run a simple ActiveRecord test I got this error:

In hind sight the answer to the problem is in the exception message, but I searched google anyway. Here's a description of the IProxyFactoryFactory change that causes the above exception. My updated config looks like this now(note the proxyfactory.factory_class addition)
|
<activerecord isWeb="false">
<config>
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" />
<add key="connection.connection_string" value="ConnectionString=${pantera}"/>
</config>
</activerecord>
|
1
2
3
4
5
6
7
8
9
|
6:5 PM Sunday Feb 15, 2009
Comments: 0
11:31 AM Sunday Feb 15, 2009
Comments: 0
11:16 AM Sunday Feb 15, 2009
Comments: 0
Here's a little sample of how I might use HtmlBuilder to generate a simple HTML table bound to a list of stuff. For convenience sake I'm just adding an extension method for the HtmlHelper that ships with ASP.NET MVC.
Here's what I want to do. Say I have a Customer class that has some simple properties. I want to write this:
|
<%= Html.Grid<Customer>("Customers") %>
|
1
|
Which spits out a [lame] table where the header contains the name of every public property on the Customer type, and the rows contain values for the matching properties for each instance in the collection of Customers passed in via ViewData.
Header Row
Here's how I build the header row using HtmlBuilder:
|
var headerRow = new Element("tr");
foreach (PropertyDescriptor property in properties)
{
headerRow.Append(new Element("th").Update(property.Name));
}
var thead = new Element("thead", headerRow);
table.Append(thead);
|
1
2
3
4
5
6
7
|
Item Rows
This is pretty straight forward.
|
var tbody = new Element("tbody");
foreach (var item in items)
{
var row = new Element("tr");
foreach (PropertyDescriptor property in properties)
{
row.Append(new Element("td")
.Update(property.GetValue(item).ToString()));
}
tbody.Append(row);
}
table.Append(tbody);
|
1
2
3
4
5
6
7
8
9
10
11
12
|
The Result
The extension method signature looks like this:
|
public static Element Grid<T>(this HtmlHelper @this, string id)
|
1
|
Notice how it returns an Element? This is handy, because since an Element is just as good as a string as far as ASP.NET MVC is concerned, you can do extra stuff. When I first ran the sample, my grid looked like this:

Looks like crap, i don't like the cellspacing issue and I want the grid a little wider. Since I am returning an Element, I can do this easily, like this:
|
<%= Html.Grid<Customer>("Customers")
.AddAttribute("style=border-collapse:collapse;width:600px;") %>
|
1
2
|
Now the grid looks like this:

Here's the sample project.
Color Banding Courtesy of Prototype.js
|
$$('table#Customers tbody tr:nth-child(2n+1)').each(function(el){
el.setStyle('background-color:#e0e0e0');
});
|
1
2
3
|
8:14 AM Sunday Feb 15, 2009
Comments: 0
8:3 AM Sunday Feb 15, 2009
Comments: 0
I was looking into the concept of DynamicProxy the other day and came across DynamicProxies by Jason Bock. Looking through his blog for info on the project, I found one entry that got an interesting comment: " ...why start a new Open Source project if Castle Project DynamicProxy already does that..."
This reminds me of a good post by Jeff Atwood the other day, Don't Reinvent The Wheel, Unless You Plan on Learning More About Wheels. I do this all the time. I wrote my own IOC container for HyperActive. Yes I could have just referenced another assembly for that functionality, but it was fun coding one of those up, I now have a better understanding of how they work.
Doing those kind of projects can also make you appreciate how much effort gets poured into some of that stuff and potentially how much better those projects are than the code you create. Several years ago, I wrote my own logging tools, sql generators, etc, etc. Today? Eff that, I'm picking up log4net or nlog, and for anything dealing with a database, it's gonna be any one of several free orms out there.
10:32 AM Saturday Feb 14, 2009
Comments: 0
I was trying to get a strongly typed ViewPage to work with my previous barebones templates and they just wouldn't work. Turns out you need a web.config in the Views directory that has a significant attribute set in pages element:
|
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Notice the ViewTypeParserFilter? After looking at the source code, it appears this guys responsibility is just to parse out the type in a strongly typed view from the a page directive. Anyway, after sticking that in the Views directory, all was good. I've updated my barebones templates to reflect the change. You can download the templates at the bottom of this post:
I'm still not sure how this works when a web.config is in the Views directory, I was under the impression that only a web.config at the root of an application is used.
7:39 AM Saturday Feb 14, 2009
Comments: 0
I started the project last March because I had seen another attempt somewhere and knew I could do better[the link to the other guy's example is now dead so I don't have that example to show]. Originally it was called PrototypeDotNetNotReally cuz it was just an experiment and I suck at project names. I had posted this library on codeplex last year, and changed its named Html. Then ASP.NET MVC came out with the HtmlHelper inside of the System.Web.Mvc.Html namespace and it collided with the name of this project. So I changed it to HtmlBuilder and posted it up at google this morning.
I'm working on some examples and the documentation and will post those in a bit. There's also a sample project console app, and I've started on playing around with a FluentHtmlHelper thingy(and yes, I know there's one in the MvcContrib project).
If you've never written code that generates HTML(or any flavor of XML), you will have ZERO interest in this library other than to take a peek at the source code, it does have 100% code covereage through the tests.
9:51 AM Friday Feb 6, 2009
Comments: 3
ASP.NET MVC ships without a project template. Instead they include an Application Starter(as the project template). The first thing I always have to do is delete all of the crap, like the extra controller, extra views, css, membership and profile shite in the web.config, etc., so I can start with a clean project template.
Removal of Scripts Directory
I prefer to have all content actually in the content folder, so I've removed the Scripts folder, and as you can see in the images below, i've just made subdirectories in the content folder for the various types of content.
HtmlHelper Extensions
I've included to extensions to the htmlhelper which are included in the Extensions folder, simple ones for stylesheet and script, and no i don't want to include a separate assembly like MvcContrib just to get that simple functionality.
|
public static class HtmlHelperExtensions
{
<summary>
</summary>
<param name="this"></param>
<param name="virtualPath"></param>
<returns></returns>
public static string Stylesheet(this HtmlHelper @this, string virtualPath)
{
string format = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />";
return String.Format(format, VirtualPathUtility.ToAbsolute(virtualPath));
}
<summary>
</summary>
<param name="this"></param>
<param name="virtualPath"></param>
<returns></returns>
public static string Script(this HtmlHelper @this, string virtualPath)
{
string format = "<script type=\"text/javascript\" src=\"{0}\"></script>";
return String.Format(format, VirtualPathUtility.ToAbsolute(virtualPath));
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
ASP.NET MVC(RC) Barebones(jQuery Edition)

ASP.NET MVC(RC) Barebones(Scriptaculous Edition)

Here's the jQuery edition template: http://panteravb.com/downloads/AspNetMvcBarebonesjQueryEdition.zip
And the scriptaculous template is here: http://panteravb.com/downloads/AspNetMvcBarebonesScriptaculousEdition.zip
I blogged about how to install the templates before, you can find it here.
|
|