kenegozi.com

<form id='kenegozi' action='post'></form>

   
2007 Nov 29

Is ASP.NET MVC Around the Corner

tagged as: monorail | asp.net ajax

Well, According to Scott Gu we'd be able to download the binaries Next Week,

 

I can't wait to put my hands on that, and start finding the possibilities of this framework in conjunction with MonoRail.

2007 Nov 27

Using the CodeGenerator and the DictionaryAdapter

tagged as: tools | castle | monorail | aspview

Following users requests, I have just posted two documents to using.castleproject.org.

The first is an explanation about the CodeGenerator (from Contrib), and another one, on using the DictionaryAdapter.

Here are the links:

 

Related stuff:

2007 Nov 20

Screen Cast - Creating MonoRail-AspView Web Application From Scratch

Following many requests from users, I've created a screen cast in which I show how to setup a new MonoRail/AspView website, from scratch (no wizards).

CreatingMonoRailAspViewWebProjectFromScratchinVisualStudioExpress.wmv

On that demo, I've used Visual Web Developer 2008 Express and Visual C# 2008 Express, both in Beta2, just to show how you can simulate some of the "Web Application Project" experience in the Express editions. Of course it's much easier to work with a full Visual Studio with Web Application Project as you then have everything in a single application, and it's easier to handle.

Nothing on the demo is 2008 specific, and it runs on .NET 2.0, so VS2005 would do just fine here.

 

The demo is very simple, and I have generally just showed a "Hello World" level of setup. I hope to spare some time to follow up with setting up things like Windsor Integration, the Castle.Tools.CodeGenerator, and other cool stuff.

 

The links I use on the demo are:

I've used Windows Media Encoder to capture the screen, and my SHURE SM58 mic to record the narrating. It's a great mic, however plugged into my sorry excuse for a sound-card.

It's my first screen cast, and I'd love to hear comments from you people, both on the content and on the presentation.

2007 Nov 19

On Linq for SQL and POCO

tagged as: linq | activerecord | nhibernate

I'm looking at the option of using Linq To SQL for persistence.

 

Basic assumptions:

  1. Entities should be POCOs
  2. I like Linq as query language
  3. I hate visible generated code
  4. Would rather avoid xml configurations

Today I'm using NHibernate (so 1 and 3 are set), and AR Attributes (so 4 is set). As for querying, I resort to hql (nice, yet too stringy), ICriteria (still stringy) and NHQG (cool, super cool, yet coupled with NH, while Linq is a "query everything" language)

 

I tried Linq for SQL (on a VS C# 2008 Express Beta2). No designer. Hand coded the entity, and have used the attributes for mapping.

 

First problem encountered: in order to make a column lazy, I need to change the underlying type to Link<MyOriginalType>, and then I can tell the context (using a LoadingOptions) about whether to load the lazy properties.

 

Couldn't yet find a way to actually lazy load that property once the instance has already been loaded.

 

I much better like the way NH is handling things, with a runtime-generated proxy that takes care of lazy loading (among other stuff), so I get it without hassling my entities code.

 

Didn't even mention First and Second Level Caches.

 

I guess I'd have to try and hop into NHibernate.Linq, and try to help Ayende with bringing it forward. That would mean diving into NH code, something I haven't done for quite some time now ...

2007 Nov 18

ActiveRecord.Linq - naive but Working

tagged as: c# | linq | castle | activerecord | nhibernate

I've spent some times lately with Linq To SQL and have played a bit with the Mapping namespace.

Why I do not like it very much is a matter for a different post. The matter at hand is that I want the power of Linq, and I want the power of NHibernate, and I want the easy road of ActiveRecord.

 

What do I mean by that? I'd like:

  1. query language == Linq
  2. persistence engine == NHibernate
  3. Mapping == ActiveRecord attributes

the needed prequisites:

  1. Linq (framework => framework.Version >= 3.5)
  2. NHibernate.Linq (source => source.getFrom(Rhino-Tools) )
  3. Linq for ActiveRecord - Keep on Reading

So, Ayende has kick-started it, and with some help from Bobby Diaz, we have a prototype level NHibernate provider for Linq.

To make it work with ActiveRecord, all you need is to add:

using System;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using NHibernate;
namespace NHibernate.Linq
{
public class ActiveRecordContext : NHibernateContext
    {
        public ActiveRecordContext() : base(null)
        {
            session = GetSession();
        } 
        private ISession GetSession()
        {
            ISessionScope scope = SessionScope.Current;
            if (scope == null)
                throw new InvalidOperationException("You should be in a SessionScope()");
            ISessionFactoryHolder holder = ActiveRecordMediator.GetSessionFactoryHolder();
            return holder.CreateSession(typeof(ActiveRecordBase));
        }
    }
}

and now you can do stuff like:

using (new SessionScope())
{
    ActiveRecordContext context = new ActiveRecordContext();
    var q =
            from c in context.Session.Linq<Category>()
            select c; 
    foreach (Category c in q)
        Console.WriteLine(c.Name);
}

Assuming Category has [ActiveRecord] mapping.

2007 Nov 15

HOWTO: Make Windows Live Writer Output XHTML Markup

tagged as: miscellanea | tools

Problem:

  • The output you get from Windows Live Writer is not XHTML, i.e. unclosed br and img tags.

 

Possible causes:

  • When you've setup your blog in Windows Live Writer, you have used a version older than Beta 3
  • Your blog's style couldn't have been detected by WLW
  • Your blog's style was been detected correctly, however you do not have a valid XHTML DOCTYPE declaration in your blog

Setting XHTML output manually:

  • Weblogs | Edit Weblog Settings | Advanced | Markup Type

 

Thanks Mr. Joe Chang, from the Windows Live Writer team, who have pointed that out for me.

2007 Nov 14

A Call for Improvements on Windows Live Writer

tagged as: miscellanea

I'm writing this very post on Windows Live Writer.

In case you'd ask, I'm using the latest public version, which is not a Beta anymore (I think):

WLW version

 

I've also just recommended WLW for a new blogger.

however, there are still some annoying things here, that I might've liked fixed.

  1. XHTML output. I said something about it, then Joe Cheng from the WLW team commented:
    WLW xhtml quote 
    However, I'd like to show you a bit from this very post :
    WLW Not closing tags
    Now you believe me?
    I believe this is a fairly simple thing to fix, as those two (img and br) are simple tags, so no need to handle nesting tags, etc.
  2. Search and Replace (Ctrl+H).
    Come on, even Notepad.exe has it.

How I wish it was an Open Source product ...

2007 Nov 13

ASP.NET MVC Framework - Demo App by Scott Guthrie

tagged as: castle | monorail | aspview

Scott Guthrie is going to present a demo application using the ASP.NET MVC Framework.

First episode is here: http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx

 

Very interesting. I can already see four things that my current VS2005/MonoRail/AspView/IIS5-6 stack lack.

  1. I do not have a project template, so setting up a new project take a bit longer than clicking "new MVC project".
  2. I do not have default rewrite rules.
  3. I cannot use Server Controls.
  4. Web Designer support when doing views is not too good. Also, layouts are not treated as MasterPages by the IDE

Sounds bad?

Well:

  1. Since I am not at kinder garden, I do not "play" with setting up new projects. When I start a new project, it would probably last for quite some time. So the time it takes me to copy&paste a minimal web.config, setup a few lines in global.asax.cs, add references and create Controllers and Views folders, costs me about 5 minutes of the global project costs.
    I can live with that.
  2. Shame. However, I can add them to my initial web.config/global.asax.cs files that I use as templates for new projects. Again - one-time cost, and not a price-i one.
  3. I do not want to use those. Didn't use them even when I was doing WebForms. I'm happy enough with ViewComponents, SubViews and ViewFilters, and I can easily use any cool 3rd party JS controllers (YUI/Dojo/jQuery/ExtJs/Moo/You-Name-It)
  4. Again - I do not trust WYSIWYG generated markup. It might be good enough for the texts on my personal blog (dear Windows Live Writer - can't you <br /> instead of <br>? what's the deal). It is definitely not good enough for any production level web site.

So - all the downsides are taken care of.

 

Plus, the stack I use is being used in production environment by gazillion people (ok, AspView is not that common, but the ViewEngine is just 5% of the whole stack, and it's the rock solid part anyway). It is working with .NET 2.0 so I need not convince clients to go for installing .NET 3/3.5 on their shared hosting solution, and since it's open-source, I can tweak stuff for my needs without the need to wait for a hotfix/ServicePack that might never appear, if not too late.

 

And if I'm not enough of a jerk for ranting like that, I'm going to try (if I'd have enough time) to put up a sample application using MonoRail/AspView similar to Scott's, but this time, you would actually be able get the bits and run it on your machines.

 

Stay tuned.

2007 Nov 13

ViewFilter - Take 2

tagged as: castle | monorail | aspview

I've been asked lately about the use of the ViewFilter mechanism in AspView.

I've once written about it briefly here on my blog, and you can see it at http://www.kenegozi.com/Blog/2007/01/08/introducing-viewfilters.aspx

 

However, I'll post another (a bit more realistic) example here.

 

Scenario: some kind of a CMS thing. You want to present the user with some markup, in both "preview" mode and "Source" modes.

 

If the server had direct access to the markup in a string literal, things were easy. That usually happens when the markup is to be supplied by an end user, either directly or through a WYSIWYG Html editor. You'd end up with something like:

public interface IContentItem
{
    public string Markup { get; }
}

your view would look like:

...
<h3>Preview:</h3>
<div><%=view.ContentItem.Markup %> </div>




<h3>Source:</h3>
<div><%=Helpers.Html.HtmlEncode(view.ContentItem.Markup) %> </div>
...

 

easy enough.

 

However, what if the piece of markup that you want to show, has some view-logic, so you have a template generating the markup from an entity? For example, this blog has a view "Posts/One" that gets a Post entity, and fits it into a single post markup, putting the title in a <h4>, tags in <span> with theit title and href, etc.

How can you show the markup source for that?

ViewFilter to the rescue.

In short - A ViewFilter is a way to transform a chunk of a view, using simple manipulations. Do not look for that on other View Engines, as it's currently an AspView-only feature.

 

Let's code our needed filter:

 

public class HtmlEncodeViewFilter : IViewFilter
{
    public string ApplyOn(string input)
    {
        return HttpUtility.HtmlEncode(input);
    }
}

and in the view:

...
<% foreach (Post post in view.Posts)  { %>
<h3>Preview:</h3>
<subview:.Posts.One post="<%=post %>" > </subview:.Posts.One>

<h3>Source:</h3>
<filter:HtmlEncode>
    <subview:.Posts.One post="<%=post %>" > </subview:.Posts.One>
</filter:HtmlEncode>
<% } %>

 

Hey - you won't even need to create that filter. AspView is supplied with four basic (however useful) filters:

  • HtmlDecodeViewFilter
  • HtmlEncodeViewFilter
  • LowerCaseViewFilter
  • LowerCaseViewFilter

Can you think of more reusable view filters? why not post them here, or better yet, supply a patch to AspView with you filters?

2007 Nov 11

Nesting View Components in AspView

tagged as: castle | monorail | aspview

Following a request from Gauthier Segay, AspView now supports nested view components.

 

scenarion: you are using CaptureFor to inject markup from a view to a layout, and you want the injected markup to include a view component output.

 

in the layout:

...
<%=CapturedContent %>
...

 

in the view:

...
<component:CaptureFor id="CapturedContent">
   Some markup
   <component:SomeFancyStuff>Fancy component content</component:SomeFancyStuff>
</component:CaptureFor>

 

While working on that, I found out yet another problem. nested components of same type would brake

so:

<component:Bold><component:Bold>stuff</component:Bold></component:Bold>

would brake.

As you probably might know, the whole preprocessing of view, from AspView syntax to standard C# is done with Regular Expressions. For quickly doing the above, I helped myself to http://puzzleware.net/blogs/archive/2005/08/13/22.aspx in order to build the balanced tags aware regular expression, and now it works like a charm. Roy Osherove's Regulator was helpful, too.

 

So, as of revision 360 in Castle Contrib repository, nesting view components works (for both the trunk and the RC3 compatible branch)

 

As usual - go to http://www.aspview.com to get the binaries, or to http://svn.castleproject.org:8080/svn/castlecontrib/viewengines/aspview/ for the sources.

 

Cheers.

2007 Nov 10

DevTeach Vancouver - I won't be there, but you should

tagged as: monorail | personal

I wish I had the time (and cash) to go there, as great speakers would host there.

Anyway - if I would've got there, I'd go for:

  • MonoRail (AGI212) by Oren Eini (aka Ayende).
    I like to go to MonoRail presentations as I learn there important stuff about presenting MonoRail to the people, and I also learn something new each time, even though I am quite seasoned with MonoRail.
  • Rhino Mocks (AGI199), again by Oren Eini. That's a mocking framework that promotes good design. I also like it's source code so I might be biased.
  • About MS MVC (ARC376) by Justice Gray. If only for the huge potential of fun and laughter, however I'm not sure that the crowd could've managed two mascu-velopers at once ...
    Seriously, this guy is funnier than the daily WTF.
  • DDD talk (ARC461) by David Laribee.
    I do not know this guy, but I do know that learning DDD would sharpen your concepts and understanding of the Object Oriented world, even if you won't actually practice DDD in real scenarios. While we're at it, I'd recommend you also get the ultimate DDD book.

 

Anecdotes:

  • MonoRail talk is on Agile track, while Ms MVC is on Architecture
  • There's a guy named Windsor there, but he won't be talking on Castle.
2007 Nov 8

AspView - AutoRecompilation mode is fully operational

tagged as: castle | monorail | aspview

If you set autoRecompilation="true" in your aspview section on web.config, then you need not use the vcompile.exe on every build. The views would get compiled in memory from sources.

Benefits: Change a view source, refresh the browser - viola, you can see he change impact. No need to rebuild the web project, the application is not restarted so no session is lost, and no need for "double refresh".

Still, when you deploy it's strongly advised that you'd run VCompile manually, copy the compiledViews.dll to the server, and set autoRecompilation="false" on the server's web.config.

 

The starter tutorial on using.castleproject.org is now updated, and you can download AspView binaries from http://www.aspview.com

 

Please use that (and other) new features and leave me some comments please ...

2007 Nov 6

Comments Are Back

tagged as: personal | blog engine

So you can tell me what you think on the new design, or any other thing (like what you think on the new changes to AspView, how you like working with the Castle stack, how great AspView is, how good looking I am, and any other kind of constructive criticism).

2007 Nov 6

Please update your feed source

tagged as: blog engine

If you're reading my blog through a feed, please update your link to http://feeds.feedburner.com/kenegozi if you hadn't yet, the web server would appreciate it.

2007 Nov 6

New Look

tagged as: personal | blog engine

sneak peek (for those who read this through a feed reader):

Sneak peek

cool huh?

Subscribe

Statistics

283
440

Related Books

Related Jobs

Related Ads

search page | Blog's home | About me