290 likes | 476 Vues
HTTP. Unneeded Abstraction. Monorail. SoC. IoC integration. MVC. Complex Lifecycle. Ken Egozi BASIC > C > Turbo Pascal > VB > WebForms > RoR > Monorail Blogs at http://www.kenegozi.com/blog/ Have created AspView, the C# View Engine for Monorail
E N D
HTTP Unneeded Abstraction Monorail SoC IoC integration MVC ComplexLifecycle
Ken Egozi • BASIC > C > Turbo Pascal > VB > WebForms > RoR > Monorail • Blogs at http://www.kenegozi.com/blog/ • Have created AspView, the C# View Engine for Monorail • Participates in Open Source projects, mainly Castle Project About Me
FindControl(“tblData”).Rows[3].Cells[2].Text = … int age; var succeed = int.TryParse(txtAge.text, out age);
URLs have meaning – R for *Resource* • /item?id=32refers to the item with id=32 • /items?category=boots&page=2refers to the second page of items, which belongs to ‘boots’ category • /boots/items/2, /item/32 same things The web is simple
Request parameters: • Within the URL (http://server/path?query) • Within the request body • The format for request parameters is:name1=value1 & name2=value2 • Arrays can be passed using • name=value1 & name=value2 … The web is simple
Common types of requests (http verbs) • GET ➔ Retrieve data from a server. The data is identified by URL. • POST ➔ Sending data to a server for storage or processing The web is simple
Common response codes • 2xx ➔ Success200 (OK), 201 (Created) • 3xx ➔ Redirects301 (Moved), 307 (Temporarily redirected) • 4xx ➔ Errors404 (Not found) • 5xx ➔ Server errors500 (General error), 503 (Unavailable) The web is simple
MVC Web Framework • Open source, with a thriving community • Built by the framework users • Built on top of ASP.NET • Caching • Session Management • Authorisation • Authentication • Http Modules • etc. • Mature, running many websites all around Monorail is a …
Simple • Maintainable • Convention over Configuration • Less code(as in: Less code, not as in: *.generated.cs) • Testable, TDD friendly Core Principles:
Action • corresponds to a group of resources (vary by query/form)In code: a plain old .NET method • Controller • A logical group of actionsIn code: a .NET class which implements IController Monorail Lingua public void Login(string username, string password) { } public class UsersController : SmartDispatcherController { }
View • A template for rendering markup to be sent to the client. • Layout • A view that acts as a container for the rendered view Monorail Lingua
Sub View • A view that will be rendered within another view. • View Component • A component that can encapsulate presentational logic and view processing. Can have several views associated with it Monorail Lingua
MonoRail WebForms Filter Common logic Simple Page’s code-behind Controller “Hard work” Business decisions DB access Web Service Page’s Markup Control’s code-behind Filter Common logic Control’s Markup View String manipulations
Sequence View Controller Model MVC GET Load() Render HTTP POST Update() Redirect Load() Render HTTP
URL •➔ Action Conventions http://www.my-cool-domain.com/post/show.aspx?id=2 Nothing new Controller Nothing new Action Aspnet_isapi.dll
URL •➔ Action http://www.my-cool-domain.com/post/show.aspx?id=2 Conventions
Monorail WebForms MVC Baked in, Simple conventions Can be added Monorail vs. Webforms Databinding Values, Classes Everything is .Text Lifecycle Simple Complex Extensible Easily (OSS), Conventions __VIEWSTATE field in the form HTTP/HTML All aspect (VERBS, Multiple forms) Single huge form, viewstate, POST API Simple, REST like hacks/SOAP/.ashx View testing Easy Impossible
Cannot Use Third-Party CustomControls? • It’s easier to squeeze the designer’s markup into a foreach/if-else than into an OnItemDataBound • Can use Third-Party DHTML/JS client libraries • How Do I Hire Developers? • Decent WebForms developers should grasp the principles quickly • You actually gain access to seasoned PHP/RoR/ASP/ developers • There’s a learning curve anyway FUD
Official view engines: • Brail • AspView • NVelocity • Contributed view engines: • Xslt • StringTemplate • NHaml View Engines
Version 1.0 is nearly out of the door • What’s missing? • Docs, • Samples, • Better Visual Studio integration • Can you help with that? Project Status
Castle Official Releases • Pro: • Official • Documentation • Stable • Wizards • Cons: • Not cutting edge • A new release will be available in the near future How To Get Monorail
Build Server • Pro: • Stable enough • Cutting edge • Cons: • No wizards • Compilation target: Debug How To Get Monorail
Build Yourself • Pro: • Cutting edge • Build options (Release? 1.1? Mono? Medium-Trust?) • Apache license => can be tailored • Patches get applied => worldwide professional recognition • Cons: • Need tools (Subversion, NAnt) • Must find a stable revision How To Get Monorail
Both are great, and better than Webforms • ASP.NET MVC’s major pros: • Larger user community • Official support ? • Monorail’s major pros: • Mature • Built by the framework users • Open source with permissive license • WAY cooler … Monorail vs. ASP.NET MVC
Website: http://www.castleproject.org • Mailing list:castle-project-users@googlegroups.com • Wiki:http://using.castleproject.org/display/CASTLE/Home Links
Blogs: • http://hammett.castleproject.org • http://ayende.com/Blog • http://www.kenegozi.com/blog • http://benl.wordpress.com • http://devlicio.us/blogs/mike_nichols • http://andypike.wordpress.com • http://jonorossi.com/blog Links