Tuesday, July 24, 2007 -
The 3rd installment in the SonicCast series is up, and I talk about the whole MVC "thing" and how we're trying to emulate that with our new SubSonic MVC templates. I also talk about how Rails implements it (a bit) and show you how you can customize our MVC templates to squeeze some tighter architecture out of your distributed app.
Your comments are very welcome!
Good cast as always. Just, please fix the code so it works in Firefox too...
Have fun, Damir
PS. I couldn't post a comment in Firefox either... DS
First two are working fine but not the 3rd.
I'll either watch it on my lappy or finally get that vmware windows image going on this box.
It's fixed - go have a look now :)
Keep up the good work, Rob. XD
..now to fix vmware.
The problem is that these are partial classes and so putting "new" in the non-generated method signature just won't achieve that - it won't even compile but well emit the message "Type x already defines a member called y with the same parameter types"
The only solution is to generate the Controller as a non-partial and subclass it in the hand-written one.
Because they will both need different names or namespaces to co-exist if you start using the generated one direct but then choose to implement something by hand you will have to go and change all your references.
[)amien
Just to verify I ran the code in the sample at it brought back a NULL product.
I need to redo the webcast anyway, so I'll be sure to run the code so you can see that it works.
Im not with a .NET compiler right now, so cannot tell you if it is possible or not.
class Program {
static void Main(string[] args) {
System.Console.WriteLine(Test.Testing());
System.Console.ReadKey();
}
}
public partial class Test {
public static new string Testing() {
return "Normal test class";
}
}
public partial class Test {
public static string Testing() {
return "Generated test class";
}
}
Which gives a compilation error that Testing() is defined twice.
The code in your sample has a underlined squiggle on the method name - it's possible it's the same error I get with this test.
I would love partials to have this behaviour but the 'new' keyword is currently for overriding inherited methods and partials are not a form of inheritance just a compile-time facility of splitting the code over multiple files/definitions.
[)amien
Doh!
I've watched the wcast (on IE7, on FF does not work for me either), and I do not get it. My fault, obviously.
The MVC pattern does not look so new to me, it just looks like a new way to call something very similar to the old three-tiered development, in the end.
when we made asp classic websites, we put all the logic in the logic tier, which in that old dark times was a clumsy activex DLL, that we called business logic.
on asp.net we put all the logic on separate classes, that we call, again, business logic classes.
accessing the data store has been made in a DAL on asp, and in a DAL (maybe made first with datasets and data adapters, then table adapters, then data entities like nHib or subsonic) on .NET.
so, all in all, what's new? It looks like this MVC thing is using an old clean and wise approach to approach to developing and giving it a new cool and shiny name. :)
where do I go wrong?
ASP and ASP.nET are not built to handle this stuff implicitly, like the Rails stack is.
A Controller is... well "in control" of your application. All events and requests are routed there to be handled - not back to the page. It plays much more of a role than just a place to put your business logic.
What we've done with these templates is go about 80% there - meaning you can't use the DAL directly, you need to use the controller classes to manipulate the object set. It's not complete, but architecturally it's preferable if you have a large system with lots of developers.
I am curious, where is the sample project for the screen cast? Could I get a copy of the project?
Thanks,
Rob Bazinet
At my work (referenced above) we struggled with asp.net and webforms much the same way you mention in the webcast. we are a huge fan of the MVC2 pattern and thought long and hard on how we could get asp.net to play nice. the front controller pattern was making it too easy to put business logic in our views. Outside of work i live in RoR, TextMate and OSX. and i desperately wanted an MVC2 framework within asp.net. so, we created one. Controllers can only be instantiated via a Request, Actions are mapped to pages and button clicks call Actions without having to wire up to the controller or an event (no more btn.Click += new blahblahblah(click_me) ) the framework handles this for you. we enforce convention, exactly the same as rails : http://mysite.com/controller/action. and we provide a nice barrier between the view and controller, you can't instantiate a controller from a view, it can only be handled via the request. we are hoping to get this framework open sourced, i'd be more than happy to share all the details and let you look at the source code if you are interested (email me if so). btw, love subsonic and this blog!
I would like to see more about your implementation. Since you didn't leave your email address I can't contact you.
Please contact me at rbazinet at gmail dot com.
-Rob
I have only used Monorail for exploring, so I am not an expert. Would it be reasonable to use their approach but replace their implementation using NHibernate with SubSonic?
-Rob
http://www.damieng.com/blog/archive/2007/08/02/partial-methods-in-.net-3.5-overview-and-evolution.aspx
[)amien
I have downloaded the templates from your previous post and after trying several times, I don't see any 'Get' methods on the controllers. There are insert, update, and mapping related methods (where available), but no 'Get' or 'Delete' method at all.
On the Sonic Cast I see you are calling 'Get(1)' on product controller.
I also opened up the ODSController template and don't see the implementation of the 'Get' methods there.
Do I have the wrong copy of these templates?
Thanks.
-Haider.
Actually, it is quite interesting. I was using the C# templates. When I looked at the VB templates, they seem to have implementation of all Fetch/get/list as well as insert/update/delete/destroy but no mapping related methods.
The C# implementation only has insert/update and mapping related methods (if available), no delete/destroy/Fetch/list/get methods at all.
Just downloaded again to make sure I have the latest copy!
Thanks a lot, Rob