# Asp.Net MVC with IronRuby - How does it work?

**URL:** <https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953>\
**Category:** IronRuby\
**Created:** [June 20, 2008, 1:57am UTC](https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953 "2008-06-20T01:57:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 20, 2008, 1:57am UTC](https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953/1 "2008-06-20T01:57:15Z")

</div>

Hi team,

I’m just trying to put together some cool samples for a DLR user group  
session i’m doing next week. Sadly, I can’t do MVC + IronRuby because  
Preview 4 isn’t out, however I was wondering if you could provide some  
technical insight into how MVC knows about IronRuby?

Does the framework host the DLR in order to make this happen? Or is it  
interacting in some other way?

Also, if anyone knows any cool demos around IronRuby (apart from  
silverlight integration and the actual language) please let me know 🙂

Thanks

Ben

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 20, 2008, 2:23am UTC](https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953/2 "2008-06-20T02:23:35Z")

</div>

Yes, there’s additional C# code involved which uses the DLR hosting  
interfaces.

For the sample that was shown at TechEd, code in Global.asax.cs executed  
“routes.rb”. This set up handlers to point to Ruby-based controllers.  
A C# RubyController class served both to delegate the request to the  
Ruby-based controller and to serve as a base class for it. A set of  
classes fronted by “RubyViewEngine” were used to read an .rhtml file and  
execute it through IronRuby.

All of this except the code in Global.asax.cs was abstracted out into a  
separate library. The only other app-specific code written in C# for  
the demo was the database access code. (And this was not because we  
couldn’t create models in Ruby.)

Naturally, the sample that’s made available with CTP 4 may look totally  
different :).

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 21, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953/3 "2008-06-21T14:34:43Z")

</div>

Thanks for your reply. Does the additional code for te DLR interfaces  
live inside the MVC framework?

RouteTable.Routes.LoadFromRuby(); \<— This creates a runtime +  
engine and executes the code (routes.rb) and adds it back to the C#  
collection. I understand how this works.

Looking a bit more at the sample, RubyControllerFactory is part of the  
MVC framework. This will also creates a runtime\engine for the  
language and be able to pass execution to HomeController.rb similar to  
how RubyRouteLoader.cs works.

Does this mean there will be a PythonControllerFactory? Why isn’t  
there just a DLRControllerFactory as the actual hosting interface is  
the same?

Once CTP 4 is out, I will be able to find out for myself, but if you  
could say if I was on the right line that would be good 🙂

Thanks

Ben

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 21, 2008, 3:40pm UTC](https://www.ruby-forum.com/t/asp-net-mvc-with-ironruby-how-does-it-work/140953/4 "2008-06-21T15:40:49Z")

</div>

None of the DLR-specific stuff is inside the same assembly as the MVC  
framework. It’s all in a separate library. [ASP.NET](http://ASP.NET) MVC is extremely  
flexible, so it’s possible to extend it in this way without modifying  
the core sources.

This particular version of the sample is extremely Ruby-specific. There  
are at least two reasons why it was written this way:

1. the DLR doesn’t yet expose a “create instance” operation through its  
public API, so there’s no language-independent mechanism for creating an  
instance object given a class object
2. IronRuby needs some work on how it exposes language features to the  
DLR

I don’t know how much that will change for CTP 4, or if we’ll have  
Python support by then. There seems to be considerably more interest in  
the community for running Ruby in IIS than for running Python, so we’re  
targeting our resources accordingly.
