vineri, 18 septembrie 2009

WordPress doesn't bother to have a nice design on Google Chrome also

So word press doesn't like Google Chrome very much. Look at how they're Apple theme behaves.










The same problem with the Search button. Guess there aren't enough Chrome users on line for wordpress to consider it being worth the attention.

vineri, 4 septembrie 2009

Did you think only Google Chrome has funny messages?

Today an interesting thing happen with firefox, it displayed the following message




Looks like Google Chrome has a competitor for those Aw, Snap! messages.

sâmbătă, 15 august 2009

IoC in .NET part 1: Autofac

This is an interesting IoC project that I used in a couple of occasions, nothing big, but I sure enjoyed it immensely.

Autofac is wrist friendly so to speak and it tries to solve your configuration problems in a simple and concise manner.

Without further ado go at http://code.google.com/p/autofac/ to get the latest version.

Next I’ll try to create a simple example that I hope we’ll use for the most part of this series.

In learning the inner workings of IoC containers we’ll develop a console application that provides some simple autocomplete for it’s features.

The features of our application are:

  • Autocomplete for internal commands
  • Commands
    • Alert – displays a message box
    • NewLine – goes to the next line
    • Calculator – with support for add

All of this features will be organized under the Components folder as functions and services.

In general you will want the concrete classes to be linked to an interface, and is by default the way I like to handle it.

A lot of voices in the community are against the use of xml files for configuration, and to that regard Autofac offers the option of using a fluent interface for configuring the builder. Although good for contracts that you are not likely to change without recompiling the application, when you need to have functionality similar to that of a plug-in you will prefer to use an IoC capable of reading xml configuration. Obviously Autofac has support for xml files as well.

Note xml configuration support is very limited in Autofac, so I’ll only show the bootstraping for this file

As I said earlier an IoC is just a form of factory, the only real difference is that this is a factory with nice configuration capabilities.

In more complex applications I recommend you use modules for configuring but for this example is sufficient to have everything configured in only one place.

As a preference I always configure the IoC I’m using in a class called Bootstrap in my highest level module ( commonly identified as the assembly containing the Main function, or if in a web app the assembly that contains the Global.asax).

The code for the Bootstrap.cs looks like this:

public class Bootstrap
{
public static IContainer Components(){
var builder = new ContainerBuilder();

builder.Register<ConsoleClearScreen>().As<IClearScreen>().SingletonScoped();
builder.Register<ConsoleWriteString>().As<IWriteString>().SingletonScoped();

builder.Register<AlarmFunctionState>().As<IFunctionState>().Named( "AlarmFunctionState" );
builder.Register<NewLineFunctionState>().As<IFunctionState>().Named( "NewLineTransition" );
builder.Register<CalculatorFunctionState>().As<IFunctionState>().Named( "CalculatorTransition" );


builder.Register<IConsoleInputService>(
c => new ConsoleInputServiceImpl(
new IFunctionState[]{
c.Resolve<IFunctionState>("AlarmFunctionState"),
c.Resolve<IFunctionState>("NewLineTransition"),
c.Resolve<IFunctionState>("CalculatorTransition")
} ) );

return builder.Build();
}
}


Autofac uses the ContainerBuilder class to register services and it offers a simple method of directly creating those services through the use of lambda expressions.



For the actual implementation of the app you can download the source code here.

joi, 13 august 2009

Checkout the Windows 7 API Code Pack for .NET

The individual features supported in this version (v1.0) of the library are:

  • Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
  • Windows 7 Libraries, Known Folders, non-file system containers.
  • Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.
  • Explorer Browser Control.
  • Shell property system.
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls.
  • Windows Vista and Windows 7 Task Dialogs.
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons.

 

More details at : http://code.msdn.microsoft.com/WindowsAPICodePack and http://www.infoq.com/news/2009/08/WIndows-7-DotNET

Javascript gotcha


Usually the style you organize code is just that A MATTER OF STYLE, in javascript however it’s not.




If by any chance you end up writing the following code:



 



var display = function() {
this.x = 10;
return
{
alert: function(message) {
window.alert(message);
}
}
}


you might be in for a surprise but it won’t return anything because by default the javascript interpreter inserts ; after every line that doesn’t already contain it or }.



Instead you should write:



var display = function() {
this.x = 10;
return {
alert: function(message) {
window.alert(message);
}
}
}


More interesting notes you can find in the next video:






Hope you enjoyed this I sure did :D.


What is an IoC ?

Disclaimer: This is a series of posts in which we’ll go through the IoC’s that are used in today’s applications

The most simple answer I can give you is this:

It’s an abstraction over Factory Method.

It helps, in my opinion to think of this as a factory method, because then you know what to expect of it, since it constructs/resolves a specific implementation based on the configuration you provide it.

In a factory method you write, aka “hard code”, the implementation you will be using. In an IoC container you basically do the same except it’s easier to change, if you write it in the xml file since using it in code leaves you with what you started and never got to changing it.

However, an IoC has an additional plus over the hand coded factory, that is “It is able to construct objects  based on the configuration you supplied”.

Does it help ?

Oh yes it helps. There’s a principle in software that states “High level modules should not depend on low level modules, both should depend on abstractions”. And guess what the principle I just stated is the Dependecy Injection Principle, it is an important point to note since IoC containers are often referred  to as Dependency Injectors. So you will probably find the IoC/DI whenever reading about an IoC.

With the help of an IoC you can declare dependencies of you object using abstractions, usually in the form of interfaces and/or base classes.

In the next part will explore a couple of IoC’s that the .NET has to offer as well as from the outside of the .NET ecosistem.

I hope that by the end of this series we can form a summary of benefits and deduct some ground rules for choosing a certain IoC, or deciding if we need it.

joi, 25 iunie 2009

Starting a simple ASP.NET Web App

Summary:

In this post we will discuss the tooling that is at our disposal and also some of the benefits or not so beneficial features it brings to the table.

 

Content

 

  • Introduction
  • Tooling
  • Benefits of using it

Introduction

ASP.NET MVC is Microsoft's way of getting on the MVC wagon. It offers a lot more control over the application you're building, no more WebControls ( personally I never and hope to never have to use it ), pure XHTML as W3C would have you doing anyways.

At this moment, and I suspect for years to come, the market of web-apps is under the heavy influence of dynamic languages like Ruby, PHP, Groovy, Python etc. Although scripting languages, a couple of strong frameworks have arisen, from them the most important of all is Rails, a MVC framework that set the bar for all the frameworks to come, so to speak. The other contestants that I find worth mentioning are Joomla (PHP), Grails ( Groovy ), Pylons and Django (Python).

We, the .NET guys, needed something like that for a while, of course there was MonoRails for years, but it didn't get enough publicity. Now there is the Microsoft's solution ASP.NET MVC, and also another project from the OSS ( Open Source Space ) called FubuMVC, wich is an opinionated front-controller style framework. I'll talk about FubuMVC in another post though.

 

Tooling

First there is Visual Studio, and then there is this add-on you have to install from http://www.asp.net/MVC/download/.

Next you have to go to File->New Project. And select from the Web category the Asp.NET MVC Web Application projec type.

 

Create-New-Project

Next you'll be displayed the following screen that let's you decide if you'll be using tests or not

Add-tests-project

For this part of the post it is not needed. Press ok and a sample project is created for you.

Let's have a look at the solution:

Screen solutionYou can see that the content is organized in

 

  • Content
  • Controllers
  • Models
  • Scripts
  • Views
There are three files left out, Default.aspx, Global.asax and Web.config. They are files that the ASP.NET engine expects to find in a web-project, kind'a like Java web-servers expect a certain layout of your project. It is a convention so we'll leave it at that.

In the Content directory you'll put your css files, images, documents and whatever else is considered to be content. The Scripts directory contains javascript files. This is the way they organize by default, you can roll your own, for instance you could have an Assets directory that has everything organized a certain way. There are no conventions so you're free to invent them.

The import part, the C in the MVC pattern, are the Controllers.They direct the flow and supply the models to the views, and that's enough of a responsability.

The nice part, the V in the MVC pattern, are the Views. They display data to the user and accept input through HTML Forms.

The core part, the M in the MVC pattern, are the Models. This layout is mostly inspired by the Domain Driven Design book, Eric Evans wrote a long time ago, but it changed the way many people, myself included, think about design.
I think that the Model part of the application is the most missunderstood part of the hole MVC pattern. The model is, in my vision, composed of the distinct parts: The Domain and The Services. The Domain is composed of entites and value objects, more info on the subject you can find at InfoQ Domain Driven Design Quickly. The Services are the business part of the model.
Don't worry I'll talk a bit more on the subject on the next part of this post.
Tools, tools and tools. If you left click a controller you'll see there's a button ready to generate the controller for you.
add-controller
Next let's create a simple EchoController.
add-controller-screen
Don select the add actions for.. since we'll not use it, just press Add. As you'll se the controller already has a Index method provided. That's a convention set in the Global.asax.cs file, by default the Index method is assumed when accesing a controller. Just to shed some light on the matter let's Debug (F5) the project. Press Ok when it asks you if you're to enable debugging on the Web.config file.

By default the Home/Index action is executed when a request is sent to the http://localhost:{development-port}/. That's because it was registered as the Default controller and action in the Global.asax.cs file. If you want to access the EchoController you'll have to write http://localhost:{development-port}/Echo. That will match the request to the EchoController and the Index action. If you do this you'll se a nice Yellow Screen Of Death.
Why? because we haven't added a view. The convention is that you have define in the Views folder, a Echo folder and add a Index.aspx page. Let's see to go about doing this. There are basically to options, but first stop the debugging ( since this is not a scripting language ).
Option No.1 By adding the folder Echo to the Views directory and Add-> View from the context menu, or Option No.2, right click inside the Index method in the EchoController class. And select Add View from the context menu. That is going to create everything for us,
and it let's us choose what type of view we want ( Details, Create, Edit, List, Empty), that's if we supply a model, but for the sake of simplicity we won't at this time


If you right click on the view, you'll have the option to go to the controller, similar, you can navigate from to the action to the view.
The rest of the tooling support is the standard editing and intellisense you've probably used with .NET previously. The Editor for the aspx pages could use alot of improvements, but that's for VS2010 I suppose.

Benefits of using it

For one you get a much richer experience since you have :

 

  • Friendly URLS
  • Alot more control over the generated XHTML and Javascript ( since you write it )
  • Easier testing of you workflow and services
  • Better separation of concerns
  • A powerfull architecture that allows you to even ditch the hole View-Engine and implement your own, or you could try Spark for a run.
In the next post I'll discuss how to set up a startup project on a simple theme that I've done with Spring MVC a couple of months back.