Castle - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Castle

Description:

It offers a set of tools (working together or independently) and integration ... MonoRail differs from the standard WebForms way of development as it enforces ... – PowerPoint PPT presentation

Number of Views:118
Avg rating:3.0/5.0
Slides: 22
Provided by: aye7
Category:
Tags: castle | webforms

less

Transcript and Presenter's Notes

Title: Castle


1
Castle
  • Manoj Waikar
  • Pune, India.

2
Introduction
  • Castle aspires to simplify the development of
    enterprise and web applications.
  • It offers a set of tools (working together or
    independently) and integration with other open
    source projects, thereby helping you get more
    done with less code.

3
Castle Stack
4
Different projects under Castle
  • Rapid Web Application Development
  • MonoRail
  • Object Relational Database Mapping
  • ActiveRecord The enterprise data mapping
    pattern implemented using Nhibernate.
  • ActiveRecord Generator - A desktop application to
    generate ActiveRecord classes based on database
    schema.
  • Inversion of Control Containers
  • MicroKernel / Windsor Container
  • Facilities
  • Components
  • Services
  • contd...

5
Different projects under Castle
  • General Tools
  • Dynamic Proxy
  • Aspect Oriented Programming
  • AspectSharp

6
MonoRail
  • MonoRail (formerly, Castle on Rails) is an MVC
    web framework inspired by Ruby on Rails.
  • MonoRail differs from the standard WebForms way
    of development as it enforces separation of
    concerns controllers just handle application
    flow, models represent the data, and the view is
    just concerned about presentation logic.
    Consequently, you write less code and end up with
    a more maintainable application.
    contd...

7
MonoRail How it works
8
MVC in MonoRail
  • MonoRail supports MVC out of the box. The
    following simple steps are needed to build a web
    application (that inherently uses the MVC
    pattern) -
  • Map the extension .rails with IIS.
  • Structure all the URLs as .../ltControllergt/ltAction
    Methodsgt.railse.g. http//localhost/intranet/hom
    e/index.rails
  • Structure your (C) projects and solutions as -
  • All the controllers in the Controllers
    sub-directory.
  • All the views (.aspx or .rails) under a Views
    sub-directory.
  • All the Master Pages under the /Views/Layouts
    sub-directory.
  • All the rescues in the /Views/Rescues
    sub-directory.

9
MonoRail Features
  • Filters
  • Filters are executed before and / or after your
    actions. It's useful for security, dynamic
    content and to keep away repetitive
    code. contd...

namespace Yournamespace public class
SecurityFilter IFilter public bool
Perform(ExecuteEnum exec, IRailsEngineContext
context, Controller controller) if
(context.Session.Contains("user"))
return true else
context.Response.Redirect("account", "login")
return false
10
MonoRail Features
  • contd...

Filter(ExecuteEnum.BeforeAction,
typeof(SecurityFilter)) public class
HomeController Controller public void
MyAction() SkipFilter public void
SomeOtherAction()
11
MonoRail Features
  • Rescues
  • Rescue is a way to associate a nice page to
    display some nasty error information.
    contd...

Rescue("generalerror") public class
HomeController Controller public void
Index() Rescue("databaseerror")
public void Save()
12
MonoRail Features
  • Layouts
  • Layouts allow you to build templates for your
    site by specifying common HTML and controls (such
    as structural HTML and navigation controls), in
    one place, that are available for any view to
    use.
  • NVelocity Layouts
  • There are other features too like Data Binding,
    support for AJAX, JavaScript validations.

Welcome! ltpgtchildContentlt/pgt Footer
13
ActiveRecord
  • ActiveRecord is a well-known pattern described in
    Patterns of Enterprise Application Architecture
    (by Martin Fowler). Basically all static methods
    act on the whole set of records, while instances
    represents each row.
  • ActiveRecord is an implementation of the (above)
    ActiveRecord pattern for .Net.
  • ActiveRecord uses NHibernate, but you don't need
    to write any fancy XML mapping as it handles
    everything for you. You just need to decorate
    your classes with attributes to declare behavior
    and meaning.

14
ActiveRecord vs. NHibernate
  • How does it differ from pure NHibernate usage?
  • Fast development (it handles the mapping and
    infers as much as it can so you don't have to dig
    into documentation or deal with tons of xmls
    everytime something changes on your schema).
  • Predefined common methods like Create, Update,
    Save, Delete.
  • Easy to implement methods like Find, FindAll,
    FindByName etc.
  • Session and transaction scopes that abstract the
    (NHibernate) ISession and translates it to a more
    natural idiom.

15
ActiveRecord Generator
  • ActiveRecord Generator is a desktop application
    that generates ActiveRecord classes (code) based
    on a database schema.
  • It currently uses OleDb to extract the meta
    information and to infer the relationships.
  • Currently works only with MS Sql Server.

16
Inversion of Control
  • A principle that dictates how you design and
    implement system components and their
    interdependencies in a way that decreases
    coupling.
  • A principle that dictates that an external entity
    should send messages to programmer's objects in
    order to perform some specialised action or to
    allow the programmer to override some logic.
  • The major difference between an object-oriented
    framework and a class library is that the
    framework calls the application code. Normally
    the application code calls the class library.
    This inversion of control is sometimes named the
    Hollywood principle, Do not call us, we call
    You. contd...

17
MicroKernel / Windsor Container
  • The MicroKernel offers an extensible inversion of
    control container core.
  • The Windsor Container aggregates the MicroKernel
    providing a simpler interface and a set of
    important features that rely on MicroKernel
    extension points.
  • The concern of the Windsor container is to offer
    a façade to the kernel and deal with external
    configuration, proxies and automatic
    component/facilities install.

18
How to use...
  • NOTE If you just need the container (no external
    configuration, no proxies) then MicroKernel is
    the right choice. However most common
    applications require the features that Windsor
    Container provides.The more straightforward
    usage is to instantiate the container and
    register the components
  • and then to get the component

IWindsorContainer container new
WindsorContainer() container.AddComponent("mail",
typeof(IMailServer), typeof(SmtpMailServer))
SmtpMailServer instance containermail as
SmtpMailServer
19
Dynamic Proxy
  • The DynamicProxy project was created to overcome
    the CLR's proxy (in)capabilities. There are
    proxies in the CLR world, but they can be
    considered a bit intrusive as it forces one to
    extend MarshalByRefObject or ContextBoundObject.
  • DynamicProxy can be used to generate proxies on
    the fly for one or more interfaces or even
    concrete classes (but only virtual methods will
    be intercepted).
  • To achieve good performance, DynamicProxy
    generates a Multicast delegate for each method
    that is going to be intercepted. Thus no
    invocation happens using reflection and delegates
    have an extremely good performance compared to
    reflection based invocations.

20
AspectSharp
  • Aspect-oriented programming (AOP) is a new
    programming paradigm that allows modular
    implementation of crosscutting concerns.
  • Aspect is an AOP (Aspect Oriented Programming)
    framework for the CLI (.Net and Mono). It relies
    on DynamicProxy and offers a built-in language to
    declare and configure aspects, and is compliant
    with AopAlliance.
  • Aspect promotes -
  • Separation of concerns
  • Code reuse
  • Decomposition

21
Related Links
  • Castle Project
  • http//www.castleproject.org/index.php/Main_Page
  • Introducing Castle 1
  • http//codeproject.com/csharp/IntroducingCastle.as
    p
  • Introducing Castle 2
  • http//www.codeproject.com/csharp/IntroducingCastl
    eII.asp
  • I want my AOP (three part series)
  • http//www.javaworld.com/javaworld/jw-01-2002/jw-0
    118-aspect.html
Write a Comment
User Comments (0)
About PowerShow.com