I’ve progressed far enough with IronRuby MVC to start thinking about a sample and I’ve decided to write 2 separate samples both on the same technologies. As an OR/M I will be using LightSpeed from Mindscape, just because it’s an awesome piece of technology.
Category Archives: IronRuby - Page 2
Ninject knows a new trick
Earlier this week Nate already said that I was doing some work on Ninject, now I have it working
. Everything I’m about to talk about is currently in the master tree of the ninject github repository. Getting IronRuby to play nice with Ninject was surprisingly easy
,
IronRuby MVC progress
If you follow my tweets or the IronRuby mailinglist then you would know that I’ve been working on taking IronRuby ASP.NET MVC from the prototype stages to a more complete application. For me this has been a great experience getting familiar with the insides of ASP.NET MVC as well as playing around with integrating IronRuby in an existing C# application.
Ruby <3 .NET – Alt.NET Italy presentation
2 weeks ago I had the chance to [talk to the Italian Alt.NET community about IronRuby](http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/). I’m pretty excited about the Ruby language and I try to convey that enthusiasm onto my victims. From the talks I had afterwards it looks like I was able to infect at least one or two enough to make them go home and download IronRuby to have a play. It is the very first time that I get to see one of my presentations myself because this one got taped and put online.
Created a basic integration for IronRuby and Asp.NET MVC
As I can see the end of the chapter on Rails and I’m looking ahead to see what will be next. I decided to start working on the chapter that talks about using IronRuby with Asp.NET MVC next. [Jimmy Schementi](http://blog.jimmy.schementi.com/) and [Phil Haack](http://haacked.com/) created a proof of concept implementation a couple of months ago that actually did work.
The past weekend I’ve been looking to build on the excellent work they did and to build a more complete integration. In this post I’ll try to explain what I did to make it work. The integration work is far from complete, so if you’ve got some free time on your hands and you happen to be looking for an Open Source project to help with then this could be a candidate for you
.
Participating in the Italian Alt.NET user group
I just finished my talk at the Italian [Alt.NET conference](http://ugialt.net).
There were the following topics of discussion:
- Domain Driven Design
- User stories & planning game
- Advanced Unit Testing in the real world
- Acceptance testing (Fitness)
And of course my topic was [IronRuby](http://ironruby.net)
Building IronRuby with Mono on OSX
**** This is a duplicate post of http://rubydoes.net/2008/12/30/building-ironruby-with-mono/ ****
IronRuby comes in 2 flavours of SCM and apparently also with 2 flavours of project layout.
I spend most of my time on the mac and I wanted to be able to test ironruby stuff on it too. I tried to build IronRuby on my mac which doesn’t work straight away you have to patch it a little to make it work. Read more »
White paper on IronRuby published
Manning published my white paper — or green paper as they call it — on IronRuby.
You can find it here: http://manning.com/free/green_carrero.html
This paper tries to give you an introduction on what the ruby language is and how it could work for you. If you want to know more than what’s on those pages there is always the book: http://manning.com/carrero
IronNails: Some progress
I thought it might be a good idea to update you guys on how IronNails is progressing. I think I’ve got it so that you aren’t exposed to writing many of the boring boilerplate code that comes with taking this approach (M – V – VM- C). Also to execute an action on a controller asynchronously you can by just adding :mode => :asynchronous to your view_action declaration.
A lot is still left to do but this proves that it is possible to use IronRuby today to do some pretty cool stuff. From the top of my head here are some things that still need to be done:
- The ability to load xaml from an assembly like the one that is generated when you use Blend for your design.
- More predefined behaviors
- Templated generators
- Silverlight support
But the core of the framework is working. Now it’s a matter of extending the functionality. Some of the features the framework does support
- Binding to controller actions through commands
- Binding to controller actions through event handlers on the view proxy
- Asynchronous execution of actions
- Timed execution of actions
- Binding to models
I will be developing my sample for my chapter against this framework and will add the pieces I’m missing as I get on.
Some of the things I foresee that might need to be added are:
- support for controlling the application from an IronRuby console so that you can interact with the interface as it is running.
- support for a console to interact with the code of the application.
- support for plugins
So after all these lists how would an application look like when you are developing it?
The controller:
# file name: demo_controller.rb
class DemoController < IronNails::Controller::Base
view_object :status_bar_message, "The status bar message"
view_action :change_message
def change_message
@status_bar_message = "#@status_bar_message appended"
end
end
The ViewModel:
# file name: DemoViewModel.cs
public class DemoViewModel : IronNails.View.ViewModel { }
The View:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="clr-namespace:IronNails.Library.Behaviors;assembly=IronNails.Library"
Title="Window1" Height="300" Width="300">
<StackPanel>
<TextBlock Text="{Binding Objects[StatusBarMessage].Value}" ></TextBlock>
<Button Content="Click me" behaviors:ClickBehavior.LeftClick="{Binding Commands[ChangeMessage]}" />
</StackPanel>
</Window>
There are currently 2 dictionaries available to the view. One that contains the models (Objects) and one that contains the commands (Commands). The value of an entry in the Objects needs to be observable by implementing INotifyPropertyChanged and that is what’s responsible for the binding syntax Objects[ModelName].Value
At this moment there are only a couple of behaviors implemented: LeftClick, RightClick, DoubleClick and Hover.
The framework expects that you follow the basic naming conventions of the technology you’re programming in. So in ruby you underscore names but in C# and xaml you camelcase them.
By defining an object with view_object
bject_name, default value you define it with a default value that you can change afterwards in the controller actions. By defining an action with view_action :action_name, :mode => :asynchronous you tell that framework that you want to link a method or a block as a controller action and execute it asynchronously.
IronNails : Rails like development for IronRuby with WPF/Silverlight
For my book IronRuby I’m working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of Witty to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF. I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github.
At first I used the name Sails for my framework but it turns out there is java clone of rails that is called opensails. So to avoid confusion David M. Peterson proposed the name IronNails.
On Sat, 02 Aug 2008 08:00:44 -0600, Charles Oliver Nutter wrote:
FYI, there’s already a framework named "Sails" for Java:
http://www.opensails.org/For the sake of sticking to the "Iron" theme, why not replace the ‘S’ with an ‘N’ and go with IronNails.
Maybed it’s just me, but if given the choice, I’d much rather nail it than sail it any day of the week.
![]()
–
/M:DM. David Peterson
You can find the project here: http://github.com/casualjim/ironnails
At this moment it’s definitely not finished at all, but it does work. The remainder of the week I’ll move my previous demo code onto this framework, update the code samples in my chapter and finish the content. I hope I will have all of this done by the end of next week.
Back to the IronNails project:
Because DLR objects cannot be used to bind to in WPF you have to define a skeleton of the ViewModel in C#, but this will change in the future. When that changes I’ll look at extending the framework to make use of some other WPF patterns like defining a DependencyObject and Behaviors. Once those are defined you get a very clean separation between design and behavior.
This is abstracted away from you but in the background the framework works with the View – ViewModel – Model – Controller pattern although I’ve tried to keep your exposure to the view model to a minimum. The framework follows naming conventions per language. So in C# and XAML you camel case stuff and in IronRuby you underscore stuff.
The very core of the framework is defined in C# but most of the code is IronRuby, depending on how hard it will be after the DLR RTM’s I may look at adding support for all the DLR languages.
IronNails
=========IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing
applications with IronRuby and Windows Presentation Foundation (WPF).
This framework uses the pattern Model – ViewModel – View – Controller (M-VM-V-C). It should be able to run on both WPF
and Silverlight.
The idea is that the views can be created using a design tool like Blend for example and just save that xaml as is. The
designer should not need to use anything else than drag and drop to create a GUI design. The behaviors are then added to
the view by using predefined behaviors in the framework or by defining your own behavior.
The framework then generates a proxy for the view which will be used to transparently wire up the commands in the
behaviors to controller actions.
You are now able to write the following code for a controller:
class MyController < IronNails::Controller::Base
view_action :show_message, :triggers => :my_button do
MessageBox.show "This is the great message from a block"
end
view_action :change_color, :triggers => { :element => :my_text_block, :event => :mouse_enter }
view_action :reset_color, :triggers => { :element => :my_text_block, :event => :mouse_leave } do |view|
view.my_text_block.foreground = :black.to_brush
end
view_object :people, Person.find_all
def change_color(view)
view.my_text_block.foreground = :red.to_brush
end
end
At this moment the project has 0 unit tests, it has below minimal documentation and it still needs a work like defining the behaviors. I have to move on with my book but intend to continue developing this framework after my book is finished and IronRuby RTM’s. There are some more workarounds in the project that will all disappear as IronRuby progresses.