Unity Application Block

I know It’s a shame, but I did not know Unity Application Block. I was searching for an IOC/Depedency Injection and a colleage advised me to learn Unity. If like me, you did not know the existence of Unity (developed by Microsoft), let’s take a look on Unity’s Codeplex website. They are some nice screencasts and a good doc on mdsn.

And you, what do you think about Unity ?

Note : I am also currently learning PRISM V.2, that’s a very interesting topic. PRISM uses Unity and it is why it’s important to understand how it works.

ASP.NET MVC C# Linq to Stored procedure with Dynamic Query (a quick phone book, piece of Cake !)

Salut les Gars !

I am back with a little code I wrote today for my business. I had to create a little phone book.

The db I had to query was pretty complicated and I did not want to create all the stuff you need for an effective Linq ot Sql classes. Therefore, I decided to use a stored procedure who retrieve all the users (about 5000) with all the information I need. This application will be a one-shot application and  his time life will be about 1 or 2 years. Also, the release date is very tight.

Read more »

C#.NET – How to extend the .NET Framework easily (extension Methods)

For example, you want a method who validate if a string is an email or not.

You create a static class, StringExtensions for example, you put it public static and you add a method who take a string and verify if it is a mail or not.

Like this :

</pre>
public static class StringExtensions
{
public static bool IsNotEmail (this string email)
{
var reg = new Regex(@"^(([^<>()[\]\\.,;:\s@\""]+"

+ @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"

+ @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"

+ @"[a-zA-Z]{2,}))$");
if(reg.IsMatch(email))
{
return true;
}

return false;

}

}
<pre>

Now back to the class where you want to use this extension.

After a dot on a string variable, you will see it in the intellisense:

intelisense_extension


string email = "tralala@something.com";

if (email.IsEmail())

{
//do something

}

That’s awesome, is that not ?

Indeed, when you put the magic word “this” in a static method insided a static class, VS will browse all the methods who take a string object in argument and will add it to intellisense.

How do I use it ?

As soon as I see that I will need a simple method for a particular type very often, I extend this type and add it to a homemade library( which contains all the extension methods I create). Of course put in your library only the standard object of the .NET framework otherwise you will get some compilation errors.

You are now able to use all the power provided by the intellisense.

For example, you have a new developer in your team. He does not need to search in the project where the functions are. He simply put a dot after his variable and he will see what is available. Moreover, if he is new with the .NET Framework, he will believe that it is included by default :) .

related link : http://msdn.microsoft.com/en-us/library/bb383977.aspx

I expect my introduction to extension methods was clear, if not, do not hesitate to leave a comment…

French blog is comming

I decide to create a french blog, I notice that they are not a lot of interesting blogs in french which talks about agile, ddd, tdd,…

So, in place to express my little knowledge in a language who is not mine, I prefer to use my native language and improve the quality of my post.

Anyway, I will keep this blog for the technical parts (C#, ASP.NET,..).

ASP.NET MVC : Url Helper Extension CSS, Javascript, Picture

Here a url helper, maybe it can interests you :


public static class UrlHelperExtension
{
public static string Image(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format("~/Content/Images/{0}",fileName));
}

public static string Stylesheet(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format("~/Content/Css/{0}.css",fileName));
}

public static string Javascript(this UrlHelper helper, string fileName)
{
return helper.Content(string.Format("~/Content/Scripts/{0}.js", fileName));
}
}

And here is how I use it :

For CSS :


<link rel="stylesheet" type="text/css" href="<%= Url.Stylesheet("reset") %>" media="all" />

For javascript


<script src="<%= Url.Javascript("jquery-1.3.2.min") %>" type="text/javascript" language="javascript"></script>

Kiwi MVC.NET : Why this, why that ? I explain my architecture choices Part 5 [source on codeplex]

So, I work hard these days to  finish my data access. I would like to explain you how I see application’s design.

As I told you before, I want to separate my application in 3 parts. I know that architecture could be discussed but I would make this point clear, it should be “re-factored”. Anyway, for the moment, I think it is enough flexible for what I want to do NOW.

Here is a reminder of my layers:

  • The Web application which will be the view of my application.
  • The controller with all my business logic embedded in a library Service.
  • The model library which will contain my models, my data access (repository) and all my filter static classes.

Read more »

C#.NET Linq to Sql : System.Data.Linq.ChangeConflictException: Row not found or changed..

I received this error during a get method (retreive the posts in my Kiwi Application).

I strangled with this during an hour and finally, I remembered that I had changed a NOT NULL field in my db to a allow null number.

So, when you do that, you simply have to update your Linq to Sql (dbml). Hope it helps.

Kiwi MVC.NET : Let’s go to TDD ! Part 4

So, now that I have introduced TDD in my Agile Page. I will try to use it along all the development of Kiwi.

Read more »

Agile – Test Driven Design “Need it or not Need it”

What my colleagues often say when they hear TDD is :  “It makes no sense”, “We do not need that”, “I am doing without TDD since ten years”.

Indeed, maybe, you do not need it. Indeed, you were doing without it but if you are a developer, you should be open to new technologies, curious and maybe you should test it before saying that you do not need it.

Main bugs come from stupid errors. If you use TDD, a lot of this (syntax, typo, omission) error will emerge quickly.

Read more »

Kiwi MVC.NET : Prepare your data access Part3

So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous post, a security layer is a kind of plugin. Therefore, we could add it later.

Today, I will show you how I am going to create the models and prepare my data access with the help of LinqToSql class.

I choose to make Kiwi multilingual.

Read more »