Castle
Optimizing Windsor
Recently we got a bug report about the performance of Windsor when registering large number of components (thousands). I decided to sit down and investigate this, and found out something that was troublesome. Internally, registering a component would trigger a check for all registered components that are waiting for a dependency. If you had a lot of components that were waiting for dependency, registering a new component degenerated to an O(N^2) operation, where N was the number of components with waiting dependencies. Luckily, there was no real requirement for an O(N^2) operation, and I was able to...
Castle Windsor 2.0 RTM Released
Some would say that it is about time, I would agree. Windsor might not be the OSS project in pre release state for the longest time (I think that the honor belong to Hurd), but it spent enough time at that state to at least deserve a honorary mention. That was mostly because, although Windsor was production ready for the last three or four years or so, most of the people making use of it were happy to make use of the trunk version. If you will look, you won’t find Windsor 1.0, only release candidates for...
Logging - the AOP way
Logging is probably the most mentioned sweet spot of AOP. Probably because it is the simplest and most straightforward example most people can think of. I remember going over a piece of code that handles billions of transactions a day(that is for you, Jdn), and seeing something like this: public void DoSomethingInteresting(string arg1, int arg2)
{
LogGateway.Enter("DoSomethingInteresting", arg1, arg2);
try
{
// actual method code
LogGateway.Success("DoSomethingInteresting", arg1, arg2);
}
catch(Exception e)
{
LogGateway.Error(e, "DoSomethingInteresting", arg1, arg2);
throw e;
}
finally
{
LogGateway.Exit("DoSomethingInteresting", arg1, arg2);
}
}
That was repeated for each and every method in the system. It was horrible.
I don't care how you do it, but there are at least 7...
Integrating NHibernate and Active Record
On the face of it, this is a nonsense post. What do I mean, integrating NHibernate and Active Record? Active Record is based on NHibernate, after all. What kind of integration you need? Well, sometimes you want to be able to use NHibernate entities in an Active Record project. And that tended to be very hard. (The other way was extremely easy, just tell Active Record to generate the mapping and move from there.) A week or so ago I added support for doing it the other way around, of adding POCO NHibernate entities into the ActiveRecord model. ...
Pain reduction: creating ductile tests
Take a look at this test: [Test]
public void When_asking_for_latest_webcast_will_not_consider_webcasts_published_in_the_future()
{
var webcast = new Webcast { Name = "test", PublishDate = DateTime.Now.AddDays(-2) };
With.Transaction(() => webcastRepository.Save(webcast));
var webcast2 = new Webcast { Name = "test", PublishDate = DateTime.Now.AddDays(2) };
With.Transaction(() => webcastRepository.Save(webcast2));
Assert.AreEqual(webcast.Id, webcastRepository.GetLatest().Id);
}
It looks like a valid test, doesn't it? It has a huge problem. It is brittle.
I just added a new non null property, and all the tests broke. I started to add the new property value to the test, before I realize what I was doing. I run into a friction point, and I was trying to cover it...
The test of fire: Rhino Mocks 3.5 in the real world
I have been waiting on the release for Rhino Mocks 3.5, seeing what kind of feedback I can get from users. I also had another reason, I hadn't had the chance to really give it a good testing, in the only manner that matter, using it to develop production ready software. Here is my latest test, which I am fairly pleased with. [TestFixture]
public class WebcastControllerTest
{
private WebcastController controller;
private IRepository<Webcast> repositoryStub;
private StubEngineContext engineContext;
private IUnitOfWork unitOfWorkStub;
private IDisposable disposeGlobalUnitOfWorkRegistration;
[SetUp]
public void Setup()
{
repositoryStub = MockRepository.GenerateStub<IRepository<Webcast>>();
unitOfWorkStub = MockRepository.GenerateStub<IUnitOfWork>();
controller = new WebcastController(repositoryStub)
...
Painless Persistence with Castle Active Record
About a year ago me and Hammett gave a few talks about Castle in JAOO. I am not sure why the recording of the talk came up now, but it have. You can watch this presentation here: http://www.infoq.com/presentations/eini-verissimo-castle-active-record For all the people who wanted to see a video of one of my presentation, there you go.
Donjon - Hammett's Teasing
Hammett has just posted teaser image on his blog. Go check it out. I have some idea about how long ago it started, and to get to this point is amazing (and no, I don't have any extra knowledge about what it does otherwise, except maybe free us from OutOfMemoryError s and manual restarts).
Active Record: Mapping Rewriting
One of the really nice things about using the NHibernate / Active Record stack is that there are so many extensions points. One of the more fun things is the ability to do runtime modifications of the mapping. Here is a simple example:ActiveRecordStarter.ModelsCreated+=delegate(ActiveRecordModelCollection models, IConfigurationSource source)
{
foreach (ActiveRecordModel model in models)
{
if(model.Type == typeof(User))
{
model.ActiveRecordAtt.Table = "MyUsers";
}
...
Castle Style Errors
I had to compare different styles of error handling approaches, and I automatically compared the ideal, Castle Style errors, to the nasty, Mystery HRESUTL of the Week. But what does Castle Style errors means? Let us take a look at a few of them. When an module that was registered before the MonoRail http module had thrown an exception: throw new Exception(
"An exception happened on Global application or on a module that run before MonoRail's module. " +
"MonoRail will not be initialized and further requests are going to fail. " +
"Fix the cause of the error reported below.",...
Model View Action
Adam has an interesting discussion here about handling common actions in MonoRail. This has sparked some discussion in the MonoRail mailing list. I wanted to take the chance to discuss the idea in more detail here. Basically, he is talking about doing this: public class IndexAction : SmartDispatcherAction
{
private ISearchableRepository repos;
private string indexView;
public IndexAction(
ISearchableRepository repos,
string indexView)
{
this.repos = repos;
this.indexView = indexView;
}
public...
Template Controllers
Sharing common functionality across controllers is something that I have run into several times in the past. It is basically needing to offer the same functionality across different elements in the application. Let us take for a moment a search page. In my current application, a search page has to offer rich search functionality for the user, the ability to do pattern matching, so given a certain entity, match all the relevant related entities that can fit this entity. Match all openings for a candidate. Match all candidates for an opening. That is unique, mostly, but then we have a...
Trusting the benchmark
I was scanning this article when I read noticed this bit. A benchmark showing superior performance to another dynamic proxy implementation. I should mention in advance that I am impressed. I have built one from scratch, and am an active member of DP2 (and DP1, when it was relevant). That is not something that you approach easily. It is hard, damn hard. And the edge cases will kill you there. But there are two problems that I have with this benchmark. They are mostly universal for benchmarks, actually. First, it tests unrealistic scenario, you never use a proxy generation framework with...
Commercial support for Castle Windsor, Castle MonoRail, NHibernate, etc
This post by Ben Scheirman is interesting. He points out that the MS.MVC stuff is targeted toward a different crowd than the one who is using MonoRail, it is targeted toward the corporate developers and the All-Microsoft Shops.
The question of support has been raised again, and it prompted this post. It seems that there isn't a lot of awareness that there are commercial support options for those tools.
Castle Stronghold is the obvious place for commercial support for Castle.
JBoss / RedHat are offering commercial support for NHibernate. JBoss no longer support NHibernate.
...
Multiple parents in Cascading Drop Downs in MonoRail
Apparently I am suffering from the Bug Duplication Syndrom. Shortly after posting about cascading drop downs in MonoRail, I realized that I have actually duplicated a bug that I have run into while using the cascading drop down extender in the ASP.Net Ajax toolkit. That is not a fixable bug, btw, and has to do with what happens when you have more than a single parent. You can see my post about this scenario here, but be aware that the solution in that post is vulnerable to race conditions, and I have finally declared that unpracticle to use. At any rate,...
Cascading Drop Downs in MonoRail
I just had this need, and I decided to explore what I could do without referring to what other people has already done. There are probably better ways, but this one has tickled my fancy. Anyway, the idea here is to display three levels of hierarchy in a profression. Here is the HTML: <table>
<tr>
<td>
${res.PrimaryProfession}
</td>
<td>
${Form.Select("primaries",PrimaryProfessions, {@value: @Id, @text: @Name, @firstoption: res.Select}) }
</td>
<td>
${res.SecondaryProfession}
</td>
<td>
${Form.Select("secondaries",SecondaryProfessions, ...
Handling javascript localization in Mono Rail
I run into the issue of having to alert the user of some error, and it brought home the fact that English & Hebrew are not easy to mix. In fact, code such as this is consider a very bad sign, usually code that you don't really want to touch, see or believe in: So, we need some sort of a way to externalize those strings, even if the only language that this application is going to use is Hebrew, simply because of the pain of mixing the two together. After thinking about it for a while, I...
And now THAT is flattering
Take a look at this Object Builder Bug, and David Hayden coverage of that bug. Extremely flattering, and a real credit to Hammett. When the criteria is: "It ain't Windsor", it says quite a bit. :-)
Open Source & Forking
Joe raises an interesting question as a result of my post about Dunn & Churchill forking a commercial version of Active Record. I mentioned that I am alright, personally, with this behavior, and he asks: Why would you be alright with that? Hammett, yourself and others have put countless hours in to the project and then these two dopes repackage and sell your work. I understand that legally it may be OK, but it doesn't pass muster in any way at all ethically. We have two different things going on here at once. I certainly don't like it, I...
Imitation is the sincerest form of flattery
Well, I guess that Castle Active Record just a whole shower of flattery. This was just posted to the Castle Forums, apparently Dunn & Churchill have a product called Diamond Binding that looks very much like Castle Active Record. There is a code project article about it here, and from the API and the license files, it looks like they have taken the Castle Active Record source and repackaged it. Now, this is allowed by the license, and this is something that I am perfectly fine at. It looks like they did some nice things with VS integration, but that is...
Active Record & MonoRail web casts
Here are the rehearsal sessions for Hammett & me at JAOO. Hammett has just published them. Not anything really new, frankly, and the quality is all over the spectrum. I was having a nasty case of the flu, especially on the MR screen cast, and that one was recorded close to midnight. You can see me recording the screen cast, that is a weird movie, I tend to move a lot when I talk, but I don't think Hammett's laptop was very impressed. Ten points if you can find the part when I kicked it.
Random Impressions from JAOO: Web Forms on the Enterprise
When Hamilton and me gave the MonoRail talk to the Enterprise Application track, we asked how many people were .NET vs JAVA vs Ruby. The results where roughly 43%, 43% and 4%, respectively. The interesting part was when I asked how many of the .NET guys used Web Forms, almost all of them said that they do. Then I asked how many enjoyed using Web Forms. No one raised their hands.
MonoRail.HotSwap in Action
Colin Ramsay has a short screen cast showing the advantages of using MonoRail HotSwap. I should mention that the startup times that you see in the screen cast are for empty projects, for real world projects they are much longer. And yes, that is how I say Ayende. :-)
Refactoring MonoRail Views
As I mentioned, I build a very quick & dirty solution to display a collection of scheduled task descriptions. The end result looked like this: This works, and it should start producing value as of next week, but I didn't really like the way I built it. Here is the original view code: <table cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>
Name:</th>
<th>
Occurances</th>
<th>
</th>
</tr>
</thead>
<tbody>
<% for task in tasks: %>
<tr>
<td>
${Text.PascalCaseToWord(task.Name)}
</td>
<td>
Every ${task.OccuranceEvery}
</td>
<td>
${Html.LinkTo("Execute", "ScheduledTasks", "Execute", task.FullName)}
</td>
</tr>
<% end %>
</tbody>
</table>
This work, it is simple and easy to understand, but it still bothered me. So I replaced it with this:
<% component SmartGrid, {@source: tasks} %>
Well, that was much shorter, but the result...
Convention over configuration: Structured approach
Hammett has a post that made me think. He is talking about configuring Spring for Java and has this to comment: I can’t understand this uncontrolled passion that java programmers carry for xml. I can certainly agree with him about that, but I got to the same point a long time ago with Windsor. I had an application which was rife with components. I am talking about many dozens of generic (as in MyComponent<T>) components, all of which required registration in the config file, which got to be fairly annoying very fast. I solved that by creating Binsor, a...
DevTech session: Storming Castle Windsor & NHibernate
I am announcing this a bit late, but I am going to give a talk about the Castle Winsdor & NHibernate on Thursday next week (03 July 2007).The anouncement has an amusing typo, I am afraid, which bring to mind some horrifying options The talk will be at DevTech, a conference that my company is arranging, so a lot of the people that I work with are going to give interesting talks. You can get more details here. Oh, and apparently I...
DSL Support for Brail
First things first, Harris Boyce III has done all the work, my sum contribution to this feature has included some wild cheering from the side lines. That said, this is one cool feature. Let us explore it. There are a lot of people who consider anything resembling <html> tags to be a mess, associate them with ASP Classic mistakes, and reject them out of hand. I think that this is a mistake, but I gave up changing the whole world overnight, now I have busy formulating three steps plans that takes a week... At any rate, consider this output: <html>
<body>
<table>
<tr>
<th>Names</th>
</tr>
<tr>
<td>Ayende</td>
</tr>
<tr>
<td>Rahien</td>
</tr>
</table>
</body>
</html>
How...
Navigating large code bases
I just needed to find an answer to a question in MonoRail. MonoRail code base is over 75,000 lines of code, including all the supporting projects and tests. Castle.MonoRail.Framework has about 37,700 lines of code. The question was something that I never really thought about, and had no idea where to start looking at. I opened the solution and started hunting. It took about five or six minutes to find the correct spot, another two to verify my assumption and be shocked that there is a private method there :-) and then I was done. Under ten minutes, to find...
The Forum Sample Application
So, it looks like the vote goes decidefully for MonoRail, so that is what I am going to build it with. I have setup a project here: https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/SampleApplications/Hibernating.Forums I have decided to take advantage of this series and show some other cool stuff that I have used, from the Repository<T> & NHQG to Binsor and MonoRail Windsor Integration. The application is basically just UI and configuration right now. I did some very rough strcuturing of the UI in a way that should...
WCF Windsor Integration
Last night I commited WCF Integration to the Castle trunk. This is based in part on the work described here by Orand. The main idea here is that WCF should get the service instances from Windsor, which gives us all the usual advantages of IoC plus Windsor's interceptors capabilities. It isn't a lot of code, but it makes it much easier to work with WCF services. Using it on a web application: Call this in the beginning of the application (Global.Application_Start): WindsorServiceHostFactory.RegisterContainer(container); Create a MyService.svc file and put this in it:<%@ ServiceHost Service="component name in windsor"
Factory="Castle.Facilities.WcfIntegration.WindsorServiceHostFactory, Castle.Facilities.WcfIntegration" %>
Have...
Castle.MonoRail.ViewComponents
So I finally found the time to build the project and put it on castle contrib. The main idea is that this is the place where community contributed view components can be aggregated, including documentation and sample code. You can get the initial stub here, it includes the Grid Component and Smart Grid Component, as well as (hopefully) thorough documentation about their usage.
Proxying Castle
From Joel Spolsky:“Google uses Bayesian filtering the way Microsoft uses the if statement,” It just occured to me that the same can be said about Castle and Dynamic Proxy. We use that from everything from AoP to strongly typed parameters support.
MonoRail and Update Panel
It seems like a MonoRail implementation of the UpdatePanel is fairly high for people coming to MonoRail from the WebForms world. I am doing a project that uses Update Panel fairly extensively, and I can see why, it is really nice way to add Ajax capabilities to your web form. I started to look into what it would take to implement it with MonoRail, and I came to two conclusions: The technical challanges on the server side are minor, on the client side it is...
What lurks in the dark corners of the Castle
I had a chat with a pal of mine recently, about why he would recommend working with Web Forms over MonoRail. The short answer was that he didn't want to end up with an ungooglable exception. The reasoning is that there isn't any nook or crany in Web Forms that hasn't been discovered, talked about, solved, and most importantly than all, indexed by Google. I don't agree with this approach, but I recognize that this is a valid way of operating. The major reason that I don't agree with this...
Windsor Patterns
I have no idea how I missed it so far, but Alex has a set of posts showing all sorts of interesting usage patterns (and design patterns) that can be used with Windsor. Part 1 - Simple Configuration Part 2 - More Configuration (Arrays) Part 3 - Still More Configuration (Dictionaries) ...
Dynamic Proxy 2: Mixins
I needed a rest from dealing with SSIS and data migrations issues, so I decided to put some time in real code. I just finished adding support for Mixins to Dynamic Proxy 2. Here is the first test that passed, the name should tell you quite a bit about what is required to make it work. [Test] ...
Hibernating Rhinos - Episode #2 - Select * From MonoRail.Customers
I have just finished putting together the second episode of Hibernating Rhinos. This one tooks several days and a lot of effort to produce. The download page is here, where you can also download the first episode, talking about Rhino Mocks. The screencast is basically taking implementing similar functionality in both Web Forms and MonoRail, while I talk about the differences between the two approaches. I spent quite a bit of time explaining most of what I do when I am writing MonoRail code, so I hope it would be clear. This episode...
Building View Components For MonoRail
While WebForms and MonoRail share the ability to refactor common UI elements into reusable components, the design decisions that should be considered for each of those is quite different. Build view components for MonoRail is much simpler than building controls for web forms, for one :-) I talked in the past about the mechanics of implementing View Components, now I want to talk about several best practices that may be useful for developers building view components for MonoRail. For this discussion, I am going to give examples from the grid component for MonoRail, whose implementation...
Brail: Complex Expressions
The technical details are going to be of interest to a limited number of people, but it comes down to a design choice that I made when I first wrote Brail. It has to do with how the text is outputted into the compiler, and some tricky bits that can happen there because Boo's compiler understand that "this is ${code}" and can turn it into the correct string, based on the value of the variable "code". That was fine until I realized that I can do more than a simple variable substitution in...
Having Fun with SmartGridComponent
I am preparing to my Dev Teach talks, and I wanted to show a cool view component. Here is a sample of how it looks like now: <% component SmartGridComponent, { ...
MonoRail With SubSonic
In the Castle forums, it was asked if it is possible to use SubSonic as the DAL for a MonoRail application. The answer is absolutely yes. You will usually see MonoRail samples with either Active Record or NHibernate, simply beacuse this is what most of the users of MonoRail are using, but MonoRail has no data access preference. (There are extention to MonoRail that make it work better with Active Record and NHibernate, but those are just that, extentions, the core is completely data layer agnostic). So, how would you...
Visual Studio Designer for Active Record & NHibernate
Gökhan Altınören has just updated Active Writer, a designer for Active Record, and now for NHibernate as well. The bits are on Castle Contrib trunk
Recommended approaches to AOP with Windsor
In my Policy Injection With Windsor (in 40 minutes), I mentioned that things like the Policy Injection Block are not a really good approach to doing AOP using Windsor. What I meant that I wouldn't build something like the Policy Application Block, simply because it doesn't really gives me anything special. The use cases for simple interception AOP are quite limited. Mostly logging, performance monitor, and that about it. But its very nature, AOP is an infrastructure entity, and will generally not take part of any meaningful business logic. Can someone think about an interesting...
Asp.net on steroids
Eber Irigoyen replied to Jeremy's and my testability posts: Jeremy Miller started a conversation on .NET testability (or the lack there of), Ayende agrees with him. I can definitely see this, I have suffered from this... but! I don't think the problem is with the tools, in any case the problem would be of the TDD community, Ruby on Rails is open source, why can't we create asp.net on steroids? seems like we know exactly what we want, the concept is there, the code is there,...
Brail Update: Fixing AmbigiousMatchException for lazy loaded classes
There is probably a bug in Dynamic Proxy that causes it to output overrides to methods in such a way that when you reflect over the generated types, you get two methods for each overriden methods, instead of a single overriden method. I looked into it in detail a while ago, and I couldn't figure out how to make it work like I expect it to. The code that it generate is verifable, so this is something that the CLR supports, but I am not quite sure that I understand what the semantics for this is....
Serialization Hurts Me
I am now adding serialization support to Dynamic Proxy 2, and it is painful. It is painful because: I never did much with serialization, and there seem to be a lot of black magic there with regard to whatever you implement ISerializable, has [Serializable] or use any of the special hooks. I am working with serializaztion by directly manipulating the IL generation. This makes for fun debugging. ...
Test First Web Development
Dan Bunea had published a very good tutorial about how to do Test First development on the web. Go visit here
MonoRail Views to the uninitiated
It looks like a lot of the people working on MonoRail has at least some RubyOnRails experiance, this means that there usualy a way for people coming from mostly WebForms background to map the concepts they know to the MonoRail lingo. Just to set the record straight, MonoRail is runing on ASP.Net platform, no perl involved. Here is a mostly random attempt to map some of those concepts, note that I am talking about views only here; Master Page...
The reason for Ajax Generators
In my last post, I show how to use the Ajax Generators, but I didn't really explain why it is good to learn yet another way to do Ajax. Here is the example that I used:page.ReplaceHtml('paginatedGrid', {@partial : 'faq/grid' }) page.VisualEffect('Highlight', 'paginatedGrid') This will send the following to the client:try { Element.update("paginatedGrid","gridContent"); new Effect.Highlight('paginatedGrid', {}); } catch(e) { alert('JS error ' + e.toString()); alert('Generated content: \nElement.update(\"paginatedGrid\",\"gridContent\");\nnew Effect.Highlight(\'paginatedGrid\', {});\n'); } (Replace...
MonoRail & Ajax Generators
I mentioned that MonoRail recently aquired Ajax Generators. The generators a are different from normal templates, because they do not generate html, but rather modify the page that was already rendered. It will be easier to exaplain with an example. Let us take the simple example of paging a grid without a full post back, shall we? By the way, this turned out to be a lot more focused at the WebForms than I intended, more on that later. Here is the backend of this demo: ...
MonoRail, Active Record & Repository<T> Sample Application
Since I was asked, here is a demo application for using Active Record and Repository<T>. Please note that this is an internal application that I use to merely test some ideas, so it is a bit rough, and there isn't any real functionality. The more interesting stuff for ActiveRecord & Repository<T> can be found in the FaqController. The entities are in Exesto.Model assembly, with all the usual attributes. ...
MonoRail Applications: Testability Expectations
Scott's has suggested that I post about the different approaches to testability in MonoRail vs. other MVC implementations. Specifically, this was caused by Scott's post about MonoRail, and a concern he raised about MonoRail and testability:I haven't seen much Model-View-Presenter framework stuff in MonoRail, but I might have missed it. I'd prefer to not have to loose the testability that comes with the pattern At first, I really couldn't see how he got to this conclution, but after a short email discussion, I think that I can see how he got this idea. And...
Building Reusable UI Components In MonoRail
I have talked recently about the problems with 3rd party controls and I made the statement that most of the time, I would want to do this on my own, since figuring out how to get to where I want with a 3rd party control often takes as much time as developing the functionality myself. Scott Bellware commented on this post, asking how to get this functionality in MonoRail. Here is a simple implementation of a grid ViewComponent in MonoRail. It supports header / footer (which the GridView doesn't), empty template, alternating rows schemes,...
Brail "new" feature, component sections...
I call it a "new" feature because it is something that the NVelocity view engine supports for quite some time. The basic idea is to allow this type of code: <?brail component BasicGridComponent, {"source": contacts}: ...
Pitching Castle
As I mentioned, there is not a very interesting discussion on the Castle Developer mailing list. One of the topics that just came up is evangelizing Castle to the community. I think that the main problem of Castle is that it help solves the problems that you have after you finished 30% of the project. That is when you start discoverring the limits of the stuff that MS is preaching. It takes prior experiance with this pain to make the trade off visible. I know that in the past I have talked about...
NHibernate Query Analayzer 1.2 Beta: Now With Active Record Support
There is a new build of NQA out, this time it works against (and only against, sorry) NHibernate 1.2 Beta 2. This time I also added support for Active Record. All you need to do is add the Active Record assembly to your project, add the app.config, and you are set. The only requirement is that the Active Record configuration section will be named "activerecord". Now you should be able to execute queries against your objects directly. This release is marked as beta, since I have not yet been able...
Demo Code for Castle Forums Demo App
I figured that no one would find the link to the code if I just put it in the end (11 pages for a single post, wow!), so here it is. You can get the sources here. Have fun!
Building Applications Using Castle RC2: Part II
Last time I left we had a working data access layer, based on Active Record, as well as a scaffolding for editing users. We used TDD to drive the functionality of the application, and I intend to keep doing it this way while developing the functionality of the site itself. Before we start by building the initial list of tests, let us consider what we want to achieve... We want to have a forum system, so diplaying the forums, adding and browsing messages is very important, but managing users...
What I find exciting, part II
I am not sure if I should feel this way, but I just finished writing a paged table in MonoRail, and that brought a complete sense of satisfaction. No, it isn't a major techincal challange. :-) It is just that I know,all the up and all the way down, what is going on, and I wholly approve. More and more I find how important it is to control as much as possible of the stack as possible. If I try to constract the code required to handle the full "get from the database,...
What should I use, NHiberante or Active Record?!
I was asked this several times lately, and it is time to try to make a more coherent statement about my thought in this matter. Active Record is a wrapper around NHibernate, which aims to make it easier to work with. The main benefit, in my opinon, is the time it takes to get a working entity from each. In NHibernate, you need to create the XML file (sorry Pierre, if I write attributes, they are the ActiveRecord ones :-) ), which can take more time than just slapping an...
Building Applications Using Castle RC2: Part I
Well, now that Castle RC2 is out, let us see what this release can do for us, shall we? After my recent talk, I got forums heavy on my mind, so let us build one. You can get the release here. I suggest that you would get the MSI installer. After installing the MSI, open Visual Studio and create a new project, you should see this screen: Choose Castle ActiveRecord Project and name the project "Castle.Forums.Model", name the solution (last text box) "Castle.Forums". Note:...
Castle Release Candidate 2 & the new Castle Stronghold
This release is not so much about new features (although there are quite a few of those there) but about making the whole project a whole lot more mature. This include stuff like: An MSI installer for Castle, so you just point & click your way through it. Project templates for Visual Studio, make it much easier to start a new project. ...
Code and Presentation from my lecture yesterday...
Can be found here. The code include all the dependencies that you need to build the project and start playing. Have fun...
Bringing it all together: Even More Magic,
So, I had done a couple of fairly cool stuff recently, but it is all in seperated pieces, let us try to bring them together and see what we get, shall we? ProjectionQuery<User> query = new ProjectionQuery<User>(Where.User.Name.Like("Ayende", MatchMode.Start), ...
Projections Support In Active Record
Ken, this post if for you... So, I have been a busy implementing crazy generics stuff and I can show you this: public class ProjectionQuery<ARType> : ProjectionQuery<ARType, object[]> Neat class, isn't it?Please not that this is not the same class that I shows here, that class has been renamed ScalarProjectionQuery, since it better fits its duy. What can you do with it? Well, things like this: ...
NHibernate Query Generator 1.7
Well, it is certainly an interesting release. This release contains very little code of mine, mainly minor adaptations of two wonderful patches that were sent to me. The first by Bas Jansen - which added inheritance detection from the mapping files. The second by Adam Tybor - which added support for projections and group by. Me, I just fixed a stupid bug by yours truly that would refuse to recognize exe...
Projections and Imports in Active Record
Ken Egozi talks about Projections and Imports in Active Record and he asks a couple of questions about it. Imports attribute poorly named: The Imports attribute is used to let NHibernate knows that it should recognize this class with a different name. Considerring the Java heritage of NHibernate, it is not surprising that it is using "import" to do this. In may be better if you could think about it as the eqiulent of: ...
Bringing Active Record and NHibernate Query Generator Together
This time, I am going to try to do it without commentry. The next post is where all the fun will begin. NHibernate Query Generator has been updated so it could work with Active Record as well. The way it works is simple, point it at an Active Record assembly, and it will spit out the generated query files. Usage: NHibernate.Query.Generator <cs or vb> asssembly.dll <output-dir> It supports generating C#...
Active Record Rocks!
I have been head down in NHibernate for the last several months, and as a result, I think that I started to miss just how enabling Active Record really is. This weekend I have been working on with it with a venegance, and I love it. The NHibernate 1.2 integration is really important, because it allows to infer even more stuff! Allow me to present, in all its glory, the amount of stuff needed to make a class persistent: The collapsed properties merely hide the get/set...
Reviewing Active Writer (Preview)
Active Writer is a DSL to design / generate Active Record classes. It is still a preview, but I have to say that after I played with it a bit, I am very impressed. Not stoned cold stunned, mind you, but the potential is definately there. I just emailed Gokhan my detailed impressions, and my #1 complaint was "I can do bulk data entry with this easily". When such a techincal product gets to the point that accessibility issue is the first thing that comes to mind, I know that quite a bit...
For the adventerous sort: Active Record + NHibernate 1.2
I branched Active Record to move it to NHibernate 1.2, because of some needed features from NHibernate 1.2 that simply do not exist in NHibernate 1.0.2. The branch at the moment should handle generics natively and easily, so you should be able to do this: [ HasMany] public ISet<Post> Posts { ... } And Active Record would figure out all the rest. (Although it is probably recommended to give it at least...
Brail Breaking Change: Removing the ?> code markers
Just read this post, talking about a problem with generating valid XML for IE using Brail. The issue is that Brail considers <? ?> as code blocks markers, thus completely disabling support for xml processing instructions. This is a breaking change in Brail, but I feel that the reason for removing them is strong enough to do so. If you have got Brail code that uses <? ?>, you need to replace it to either <% %> (not recommended) or <?brail ?> (recommended, valid XML). If this is a really big issue...
More On Binsor: Natrual Component References
Well, I just added the last piece in what I consider the major features to Binsor, which is component references. I'm a big fan of decorators and chains of responsabilities, which mean that I tend to create a lot of references between objects. In Binsor, it is as natural as this: import Rhino.Commons ...
Introducting Binsor: The Boo DSL For Windsor
On the on-going battle between yours truly and XML, there has been a score on the good side! I just finished implementing most of the usable functionality in Binsor, which is a Boo DSL* that is directed at configuring Windsor. Before I get into the details, take a look at the most minimal xml configuration possible for Windsor: <?xml version="1.0" encoding="utf-8" ?> ...
I want one of those: Active Writer - VS Designer for Active Record
Check out the pretty pictures! Even better information at the source. Gokhan Altinoren has done some tremendous work there. Can't wait to get the bits.
Bill Pierce On Windsor
Bill has a couple of interesting posts about using Windsor as the basis for an MVP framework for ASP.Net MVP Framework UserControl Component Activation in Castle MicroKernel
Castle And The Open/Close principal
Recently I have been trying to use Castle Windsor to make me a cup of coffee. So far I managed to gray screen the coffee machine, but I am okay with this limitation, since it is just about the only thing that I can't do with it. The scenario, I have a set of similar services that I want to load from configuration. They all implement the same class, but have different configuration, here is a sample:public WebService(string url, DateTime start, DateTime end) My first attempt to solve this issue was with this configuration: ...
Sanity Checks: The Active Record Version
Following my NHibernate Sanity Check, here is the Active Record version: public class AR_Sanity_Checks : ActiveRecordModel { public static void DoSanityCheck() ...
If a tree falls in a forest and there is no one there to hear it fall does it make a noise?
According to my code, it doesn't. Here is the scenario, the scenario is supporting on the fly view updates for Brail. Recent changes in MonoRail meant that loading the view is now the responsability of the framework, and not the responsability of the view engine. This, however, presented a problem. Brail's view are compiled classes, but I want to allow edit & refresh cycles, so I can't force the develop to restart the application every time a view change. So far, I handled it with a FileSystemWatcher that took care of...
Castle's Continious Integration
In due time, and after some difficulities due to annoying mail servers, Castle now has a Continious Integration process that works. :-) You can see the daily builds here: http://castleproject.org/~ayende/
Castle And Bicycle Riding
A while ago I was trying to explain the benefits of Castle to developers, and I just couldn't get through. It is pretty easy to explain the benefits of using Active Record, but I had a hard time explaining MonoRail and Inversion Of Control. Here is my elevator speach for MonoRail:MonoRail is RAD MVC framework built on ASP.Net that supports the Front Controller pattern and force strict seperation between UI and Business Logic. I got into a lot of problems with this, since it doesn't convey the benefits to the people I am...
The Value Of Reuse
Hammet has posted a comment from his article about Castle. The comment basically talks about reuse in NVelocity, one of the MonoRail's View Engines. NVelocity is not a full fledge programming language, and that means that you can't do some things that you can do with a full langauge (at least not easily). The end result is that you really don't want to write TheUberGrid in NVelocity, so you may end up writing a one-off, per scenario template, instead of a general control that can accept anything you throws at it and...
Casle Demo App: Midway Summary
I tried to get an overview of all the posts I wrote so far about Castle Demo App, and I got a little lost, and I guess that this isn't only my problem, so I put up a list of all the posts in the subject. I must say that I was very surprised to see that I posted so much about this (and I can think of several more topics that I want to post about). So, without much further ado, here is the list as of right now: ...
MonoRail, MVC and ASP.Net
I run into this post, comparing MonoRail and ASP.Net 2.0, which I thought was interesting. I'll start by saying that I mostly disagree with the conclutions. Rodel is making a mistake by comparing the feature sets. The difference between ASP.Net & MonoRail is not something that you can break down by features. They are mostly comparable anyway. The issue are with the level of control, the amount of abstraction you have and the programming model you are working with. The problem with ASP.Net is when you start to deal with complexity. For simple...
Castle Demo App: ViewComponents, Security, Filters and Friends
In this post, I'm going to explain how to secure the administration section of the site. Since the pages in our application do not map to a directory structure on the server, the ASP.Net default security isn't going to help us (I'm not entirely sure about this, though). Because of the way that the MonoRail is built, we often can make security decisions about the all the actions in a controller. Such is the case with the AdminController, only administrators should be able to access this page. Currently, we don't have the...
Castle Demo App: Code Update
I've updated the code that is avialable. Now I also bundle the parts of Castle that you need in order to run it, so you will have easier time build and testing this code. All the binaries you need can be found in the Deps directory, you'll need to change the references to point to that directory. You will also need SQL Server or SQL Express for the database, as well as .Net 2.0. You can get the new release here (1.2Mb).
Castle Demo App: Queries and Foreign Keys
Okay, one thing that I'm sure that you have noticed is that we have a bug in the DeleteUser method. The problem is that we don't check for foreign keys violations, and that will cause problems down the road (someone tries to delete a user that is assigned to a project, and he suddenly stares at an error page asking "But what did I do?" Let's try to prevent it before we get a bug report about it. First, we need to make a couple of policy decsisions. There are two ways that...
Castle Demo App: Complex Interactions
Castle Demo App: Complex Interactions We have CRUD operations for users and projects. The next step is to add a way to assign / remove users from a project. We can do it both for users and projects, but this is just overly complex. We're going to allow a project edit page to add or remove users, and that is all. I'll be the first to admit that I'm not very good with JavaScript, and I've practically no knowledge in the Ajax capabilities of MonoRail (which are based on Prototype library). I'm just going to...
Castle Demo App: CRUD Operations on Projects
I thought about leaving the CRUD for Projects for the readers, but when I started to implement it myself, I realized that there were several things here that I hand't explained. As a quick note, I made some modifications to the code, to structure it better, there shouldn't be any changes to functionality, but I added a few utility functions and made some of the views more generalized. In general, those changes are from having NoSuchUser and NoSuchProject views to having a single NoSuchObject view, nothing more. Okay, let's talk about projects. A project...
Brail Update: Nullable Parameters
Okay, so I run into a couple of problems with NUnit versioning, but it's here. I added support for nullable parameters in Brail, so now you can do:${?user} And if the user has not been set, it'll return null. You can get the latest bits here. I won't publish a Castle Demo App today, but I'll certainly attempt to use the new feature tomorrow in the Ajax part.
Castle Demo App: Let There Be A New User
Before we start with our regular content, a couple of bug fixes, the ValidateLength on the Name and Email properties of the User class should looks like this: [ ValidateLength(0,50)] Specifying just one number means the exact length of the string. Okay, so far we have seen how to edit users and then save them to the database, but we haven't seen yet how to actually create the users. For myself, I think...
Brail Update
Okay, I got around (finally!) to work a little with Brail, and the end result is that there were a plenty of improvements: Removed useless error handling from Brail, now you'll get the noraml ASP.Net Yellow Screen Of Death on errors. More consistent with the rest of the framework. I can't really understand what I was thinking when I added this. Added support for <?brail ?> tags for Brail, so it can be valid XML...
Castle Demo App: Updating our Users
Okay, here we go again. One thing that I forgot to mention in the last post is how you access the pages you created. You simply need to use the following URLs: http://localhost:8080/admin/users.rails http://localhost:8080/admin/projects.rails Before we continue, a couple of words. When I started this series, I had the intention to make it possible to use this with the latest...
Castle Demo App: Getting serious, the first real page
Okay, so far we played around with MonoRail, and I, at least, has quite a bit of fun. Just to point something out before we carry on: While MonoRail has strong scaffolding capabilities (the ability to generate pages for CRUD operations automatically), I don't like the idea of using them, we're going to build everything from scratch. The first thing that we need to do is to add is some wrapper HTML so our pages will not be HTML fragements (like the previous one). We do it by specifying a layout. Layouts...
Castle Demo App: MonoRail At A Glance
Okay, so far we saw that MonoRail can be used to serve static files just as well as a 1993 Gopher Server. Considerring that Gopher is dead, we might want to add some stuff to our application. But allow me to give you a very short overview of the way MonoRail works. MonoRail has Controllers and Views. A controller is a normal class that inherit from the Castle.MonoRail.Framework.Controller class. When a request comes in, MonoRail analyze the URL and dispatch the request to the proper controller method. This is important, unlike in...
Castle Demo App: The First MonoRail Page
So we finally made it to actually talk about MonoRail. :-) Just to set the expectations straight, we are going to create a web site for to the Mythical Bug Tracker application, using MonoRail and Brail. It's going be functional, but it is not going to look pretty. I'm not a designer, and I'm not going to waste my time talking about CSS and color coordination when you can go to someone who actually knows something about them and learn something useful. In two sentences, what is MonoRail? MonoRail...
Found VS.Net & FileSystemWatcher problem
Like I said, I had a problem with the FileSystemWatcher not picking up the changes that VS.Net was doing.
Justin suggested playing with the NotifyFilter property, and it worked! The issue turned out to be that VS.Net doesn't write to the file, but rather copy a temporary file that it keeps on the side over the file. All I had to do was to add the NotifyFilters.CreationTime and it worked.
I noticed the problem while working with Brail, and I'll commit the stuff tonight. It does mean that to be able to really play with my Castle Demo App, you'll need to use...
Castle Demo App: Many To Many Relations
We have users and we have bugs, but it is still not enough to create a good application, we need to group the bugs to projects, and we need to be able to assign users to projects. So, without further ado, let’s write the Project class. What do we need to have in a project? The project name, the default assignee (remember that all bugs are assigned always.), the bugs in the project and the users working on it. With that said, let’s start with building a simple Project class. ...
Castle Demo App: Lazy Loading and Scopes
First, a bug correction, in an earlier post I said that the user's OpenBugs property should be initalized exactly the same as AssignedBugs, this is a mistake, it should be initialized like this: _openBugs = new EntitySet<Bug>(); The reason for this is that addition/removal to the OpenBugs shouldn't affect the AssignedBugs collection, which is what I accidently did. Okay, so now we have Users and Bugs (they...
Castle Demo App: Active Record Relations
For this part, I'm going to use NHibernate.Generics, which is an extention to NHibernate that allows to use generic collections for relationship between classes. You need to download it from here and add a reference to: NHibernate.Generics.dll Iesi.Collections.dll Okay, so we have a User, now we need a Bug class, so we can store the information about our bugs. I'm going to skip the parts that I've already covered and move to...
Castle Demo App: Getting Started With Active Record
A few words about Active Record: Active Record is a wrapper around NHibernate, which is an Object Relational Mapping for .Net. I'm not going to explain how things works in this post, just how to use them. If you're going to be a serious Active Record user, I'm strongly recommend that you'll learn how to use NHibernate. You'll appriciate how much Active Record does for you much more afterward. Setting The Environment: Assuming that you already have the Castle's binaries on your machine, let's start by creating a class...
Building a full blown application with Castle
Recently I'd a couple of IM conversations with people who wants to build applications with MonoRail & Brail, but there isn't any useful sample application for that. There is Castle's Samples, but they don't cover Brail, and there doesn't seem to be a step-by-step tutorial for creating a full application using Castle. The Pet Store example covers most of Castle, and it certainly helps, but some people like to read tutorials better than look at the code. I'm going to try to...
Castle Samples
I just realized that there is a wealth of sample applications for all the parts of Castle. You can view those sample applications online here (or by just downloading the source and looking in the Samples directory). I tend to just read the Castle source until I find the right answer, I never thought about looking at the samples :-) There is quite a lot of information there.
Castle has a new home page
My favoriate open source projects just got a new design for the web site.It's looking cool!
Brail is Kicking one more :-)
For the last 20 days or so, Brail wasn't part of the Castle's build, beause of the changes in how testing is done. It took me some time, mainly because I couldn't really devote any real length time to this. So now Brail's tests support the Castle.MonoRail.TestSupport, and I can investigate some interesting changes that were made in both Boo and the view engine for MonoRail.
Correnting My Mistake: Static Methods & Child Classes
In a previous post
I said that you can't "inherit" static methods from your parent class.
Apperantly I was mistaken. The following code works on both 1.1 &
2.0: public class Parent { public static void Static() { } } public class Child : Parent { ...
Static Generic Class
Now this is a cool feature I just discovered. I don't think that
this is the true name, but it describe what it does. I'm currently
trying to give ActiveRecord
a more .Net 2.0 interface, and I'm currently concentrating on the
static methods of the ActiveRecordBase class. The current best practice
for ActiveRecord is to create a type safe wrapper on your class when
you're inheriting from ActiveRecordBase. The reasoning is very simple: Blog []blogs = Blog.FindAll(); ...
Brail Beta 2
I’m very pleased to announce that Brail now uses the white space agnostic derivative of Boo, which makes for much better syntax when mixing with the web. Check out this syntax to use a block component: <% component MyViewComponentWithBody: %> html content <% end %> A lot of thanks to Rodrigo, for creating Boo in the first...
MonoRail makes life boring...
How can I take pride of solving hard problems when MonoRail takes them all away? I'm trying to build a sample bug tracking system. The problem is that I'm using MonoRail, which means that I'm in either of two states: The explorer state - where I just surf MonoRail code and discover all sorts of cool things it can do for me. This is the fun part. The implementation state - where I try...
Boo & Active Record makes for strange bedfellows
Just check out the syntax to declare a property that is also a primary key: [Boo.Lang.Property(UserId, Attributes:[PrimaryKey(PrimaryKeyType.Native, "id")])] userId as int The probably proper way to do it would be to ignore the magic Boo.Lang.Property attribute and do it the old fashion way: userId as int ...
Brail & Castle Project
Brail is now officially a part of the Castle Project :-) I added it to the source repositoy yesterday and today I've finished (with a lot of help from the Castle community). The documentation is now located here. The source repository is here. One interesting thing about the Castle community, they really do practice shared source and collective ownership. I still need to get used to it, I think.
I'm a Castle Commiter!
I've been voted as a commiter for the Castle Project. You might recall how excited how I was when a patch I made was accepted for Catle, so you can imagine how I feel right now about it. :-D Along with this there is another big issue: Brail has been accepted into Castle's MonoRail and will now be available as part of their services. So I would finally have a public Subversion server that I can point people to. I'm going to update everything in the site and upload the repository tomorrow. I...