tag:blogger.com,1999:blog-25048658841106595512024-02-08T10:25:00.970-05:00code that worksideas on .net programmingSylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-2504865884110659551.post-86970843882710915602013-06-20T21:11:00.001-04:002013-06-21T07:52:22.182-04:00karma webstorm configuration<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: blue; font-family: Arial; font-size: 12px; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Versions : WebStorm 6.0.2, Karma 0.8.5</span></div>
<b id="docs-internal-guid-5fb55c4f-6448-78bd-33cb-0f94e9efae0f" style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In this short post I'll just explain my WebStorm configuration to run my Karma tests inside WebStrom. It's quite simple but can be useful.</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: #999999; font-family: Arial; font-size: 15px; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">These steps assume you can already use </span><span style="background-color: #666666; color: lime; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">karma start</span><span style="background-color: transparent; color: #999999; font-family: Arial; font-size: 15px; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> at the command line to start watching your project and run your tests. If you don't and wish I'd write a post on that, just let me know in the comments...</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1 - Create a new Run configuration for Node.js.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">2 - Set the Working Directory to your project root.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">3 - Set Path to Node App JS File to the Karma executable. </span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Type </span><span style="background-color: #666666; color: lime; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">which karma</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> (or </span><span style="background-color: #666666; color: lime; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">where start</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> in Windows) at the command prompt to find Karma's location.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">4 - Set Application Parameter to the value : </span><span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">start</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">5 - Click Ok.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">6 - Select that config in the config drop down.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">7 - Click run and see your Karma results right in WebStorm!</span></div>
<br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Have fun!</span><br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com0tag:blogger.com,1999:blog-2504865884110659551.post-47016845875524899752013-02-04T08:52:00.001-05:002013-02-04T08:57:10.770-05:00How to synchronize Sublime Text settings across several computersThis will synchronize all settings and installed packages across multiple machines using Dropbox.<br />
<h3>
On the first computer</h3>
<ul>
<li>Close Sublime Text 2</li>
<li>Copy <code>C:\Users\<b>you</b>\AppData\Roaming\Sublime Text 2\Packages</code> to your dropbox folder (<code>c:\Dropbox\Sublime Text 2\Packages</code>)</li>
</ul>
<h3>
On all computers (including first computer)</h3>
<ul>
<li>Delete the Packages folder <code>C:\Users\<b>you</b>\AppData\Roaming\Sublime Text 2\Packages</code></li>
<li>Create a link to your Dropbox folder :
<pre>cd C:\Users\<b>you</b>\AppData\Roaming\Sublime Text 2</pre>
<pre>mklink /D Packages "<span style="white-space: normal;">c:\Dropbox\Sublime Text 2\Packages</span>"</pre>
</li>
<li>
Start sublime
</li>
</ul>
<br />
Note: It works the same way on Unix computers using the <code>ln</code> command. On Linux the path is <code>~/.config/Sublime Text 2/Packages</code>.
Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com0tag:blogger.com,1999:blog-2504865884110659551.post-41362673061171380752012-06-14T13:17:00.000-04:002013-07-24T22:46:58.145-04:00Simple-expand: simple jQuery plug-in to expand/collapse elementsSimple-expand, as its name implies, the simplest collapse/expand solution I could think of. It works out of the box without any configuration.
All you need is:
<br />
<pre class="prettyprint"><a class="expander" href="#">click me</a>
<div class="content">
content to show/hide.
</div>
</pre>
And one line of javascript:
<br />
<pre class="prettyprint">$('.expander').simpleexpand();</pre>
<a href="http://sylvain-hamel.github.com/simple-expand/" style="background-color: #ffae00; border: 1px solid #8C8C8C; color: white; display: block; font-family: Verdana, sans-serif; font-size: x-large; padding: 14px; width: 150px;" target="_blank">View Demos</a>Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com11tag:blogger.com,1999:blog-2504865884110659551.post-33028298206888612722012-05-29T20:06:00.000-04:002012-05-30T13:55:45.062-04:00Responsive full height (equal height) columns using the faux columns css technique<h2>
Source code on GitHub</h2>
<div>
First things first, here is the source code.</div>
<a href="https://github.com/redhotsly/responsive-faux-columns">View project on GitHub</a><br />
<h2>
Introduction</h2>
In this tutorial I'll show you how to create responsive full height columns using the "faux columns" technique.<br />
There are 3 main concepts in that:<br />
<ol>
<li><b>Full/Equal height:</b> When you float an element, its height is equal to its content; not to its "context". This causes a problem if you want a sidebar that has a different background-color than the main area because the background will not extend to the same height as the other column(s).</li>
<li><b>Faux column technique: </b>This is a technique that uses a background-image to create an effect that looks like the column extends to the full height. This technique has been documented several times but this article is a bit different because of the following point.</li>
<li><b>Responsive: </b>With responsive design, the width of the page set to a fixed size (such as 960px). Instead the content of the page adapts as your make your browser window wider or narrower. </li>
</ol>
So this tutorial is about using the faux column technique but with the necessary tweaks to make it work in a responsive layout.<br />
<h2>
The HTML:</h2>
The page has a header div, a main div and a footer div. The main div has an article div and a sidebar div on the right side. <br />
<pre class="code"><span style="color: blue;"><</span><span style="color: maroon;">body</span><span style="color: blue;">>
<</span><span style="color: maroon;">div </span><span style="color: red;">class</span><span style="color: blue;">="page">
<</span><span style="color: maroon;">div</span><span style="color: blue;">>
</span>header
<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">>
<</span><span style="color: maroon;">div </span><span style="color: red;">class</span><span style="color: blue;">="main clearfix">
<</span><span style="color: maroon;">div </span><span style="color: red;">class</span><span style="color: blue;">="article">
</span>Main content
<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">>
<</span><span style="color: maroon;">div </span><span style="color: red;">class</span><span style="color: blue;">="sidebar">
</span>sidebar
<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">>
</</span><span style="color: maroon;">div</span><span style="color: blue;">>
<</span><span style="color: maroon;">div</span><span style="color: blue;">>
</span>Footer
<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">>
</</span><span style="color: maroon;">div</span><span style="color: blue;">>
</</span><span style="color: maroon;">body</span><span style="color: blue;">></span></pre>
<h2>
The CSS:</h2>
<h3>
1 - Define the <span style="color: #c0504d; font-family: 'Courier New';">clearfix</span> class to help us clear the float.</h3>
There are several ways to clear floats. The technique I use here it the one used in the <a href="http://html5boilerplate.com/">HTML 5 Boilerplate</a> project. See <a href="http://nicolasgallagher.com/micro-clearfix-hack/">this blog post</a> to learn about that specific technique.<br />
<br />
<pre class="code"><span style="color: maroon;">.clearfix </span>{ *<span style="color: red;">zoom</span>: <span style="color: blue;">1</span>; }
<span style="color: maroon;">.clearfix:before</span>, <span style="color: maroon;">.clearfix:after </span>{ <span style="color: red;">display</span>: <span style="color: blue;">table</span>; <span style="color: red;">content</span>: <span style="color: blue;">""</span>; }
<span style="color: maroon;">.clearfix:after </span>{ <span style="color: red;">clear</span>: <span style="color: blue;">both</span>; } </pre>
<h3>
2 - Define the two columns using a 70/30 ratio.</h3>
<pre class="code"><span style="color: maroon;">.article </span>{
<span style="color: red;">float</span>:<span style="color: blue;">left</span>;
<span style="color: red;">width</span>:<span style="color: blue;">69%</span>;
<span style="color: red;">padding-right</span>:<span style="color: blue;">1%</span>;
<span style="color: red;">overflow</span>:<span style="color: blue;">hidden</span>;
}
<span style="color: maroon;">.sidebar </span>{
<span style="color: red;">float</span>:<span style="color: blue;">right</span>;
<span style="color: red;">width</span>:<span style="color: blue;">28%</span>;
<span style="color: red;">padding-left</span>:<span style="color: blue;">1%</span>;
<span style="color: red;">padding-right</span>:<span style="color: blue;">1%</span>;
<span style="color: red;">overflow</span>:<span style="color: blue;">hidden</span>;
}</pre>
<br />
Setting the overflow to hidden is not mandatory but I think it looks better when you resize the browser so small that content cannot be wrapped.<br />
<h3>
3 - Add the faux column effect by setting a background image</h3>
This is the key part.<br />
<br />
<pre class="code"><span style="color: maroon;">.main </span>{
<span style="color: red;">background</span>: <span style="color: blue;">url(opaque-0.70-5000.png)
repeat-y
70%
top</span>;
}</pre>
<br />
Note that:<br />
<ul>
<li>The background image is set for the main div; not the sidebar div.</li>
<li>The background image is 5000px wide by 1px high.</li>
<li>The width of the image determines the maximum width that your page will support; beyond that point the faux column effect will break (you can use a larger image if you want but 5000px is really wide).</li>
<li>The height of the image does not matter. If you use an opaque color, then 1px is enough. If you want to use a pattern then you can use a taller image.</li>
<li>In the image, the column start at 70% of the width of the image, at pixel 3500 (5000 * 0.7 = 3500).</li>
<li>The 70% value in the css is the position of the image. Use the same value as the ratio.</li>
</ul>
This works with any image width. The only thing that matters is you have to start the column effect at the right pixel. For example, if you have a 3000 pixel wide image, your column effect should start at pixel 2100 (3000 * 0.7 = 2100). This example does not fill the right side; there is just 1 pixel at position 2100, which create a vertical line.<br />
<br />
<pre class="code"><span style="color: maroon;">.main </span>{
<span style="color: red;">background</span>: <span style="color: blue;">url(line-0.70-3000.png)
repeat-y
70%
top</span>;
}</pre>
<h3>
4 - Set a max width for page and add some spacing</h3>
As stated in the previous step, the width of the image determines the maximum width the page support. To ensure it will not break beyond that point I set a max-width on the page div. If you don't like the way your site looks when it is very wide, you can set a max-width of 1600px (that's what I usually do).<br />
<br />
<pre class="code"><span style="color: maroon;">.page </span>{
<span style="color: red;">width</span>:<span style="color: blue;">75%</span>;
<span style="color: red;">margin</span>:<span style="color: blue;">auto</span>;
<span style="color: red;">max-width</span>:<span style="color: blue;">5000px</span>;
}</pre>
<h3>
5 - Responsive with media queries</h3>
You can use css media queries to change the ratio of the columns based on the browser width and for the faux column to work, you will have to change the background image too. For example, if you want a 75/25 ratio when the page is narrower than 600px, you have to:<br />
<ol>
<li>Create a background-image with a ratio of 75/25. For a 600px wide image, the column must start at pixel 450 (6000 * 0.75 = 450).</li>
<li>Add media query, change background-image and change the column ratio:</li>
</ol>
<pre class="code"><span style="color: blue;">@media </span>screen and (max-width: 600px)
{
<span style="color: maroon;">.page </span>{
<span style="color: red;">width</span>:<span style="color: blue;">95%</span>;
<span style="color: red;">margin</span>:<span style="color: blue;">auto</span>;
<span style="color: red;">max-width</span>:<span style="color: blue;">600px</span>;
}
<span style="color: maroon;">.main </span>{
<span style="color: red;">background</span>: <span style="color: blue;">url(opaque-0.75-600.png)
repeat-y
75%
top</span>;
}
<span style="color: maroon;">.article </span>{
<span style="color: red;">float</span>:<span style="color: blue;">left</span>;
<span style="color: red;">width</span>:<span style="color: blue;">74.5%</span>;
<span style="color: red;">padding-right</span>:<span style="color: blue;">0.5%</span>;
}
<span style="color: maroon;">.sidebar </span>{
<span style="color: red;">float</span>:<span style="color: blue;">right</span>;
<span style="color: red;">width</span>:<span style="color: blue;">24%</span>;
<span style="color: red;">padding-left</span>:<span style="color: blue;">0.5%</span>;
<span style="color: red;">padding-right</span>:<span style="color: blue;">0.5%</span>;
<span style="color: red;">overflow</span>:<span style="color: blue;">hidden</span>;
}
}</pre>
<h3>
Conclusion</h3>
I learned a lot in the process of writing this post. I don't consider myself an expert on the matter. Don't hesitate to leave comments if you think the solution can be improved and I will update the post accordingly.<br />
<br />
Don’t forget that you can <a href="https://github.com/redhotsly/responsive-faux-columns">browse the code on GitHub</a>.Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com11tag:blogger.com,1999:blog-2504865884110659551.post-23480982867394412252012-05-22T22:04:00.000-04:002012-05-29T17:49:31.554-04:00Build Twitter Bootstrap on Windows<i><span style="color: #351c75;">This post is written using these tools and libraries: Twitter Bootstrap 2.0.3 | nodejs version 0.6.18 | lessc nodejs module version 1.3.0 | uglifyjs nodejs module version 1.2.6.</span></i><br />
<i><span style="color: #351c75;"><br /></span></i><br />
<b>Intro</b><br />
In this very short post I explain how to build twitter bootstrap on windows.<br />
<br />
<br />
<b>1 - Get the source from github</b><br />
If you go to the <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap main page</a> there are several download options. In this case you want to download the source code. Click the <b>View project on GitHub</b> button or visit <a href="https://github.com/twitter/bootstrap/" target="_blank">https://github.com/twitter/bootstrap/</a> and download the latests version using the ZIP button (or clone the repo using git). Extract the ZIP.<br />
<br />
<b>2- Install nodejs and the necessary modules</b><br />
2.1 - Install nodejs (see <a href="http://codethatworks.blogspot.ca/2012/05/install-node-won-windows-with-npm.html">Install Node on Windows with NPM tutorial</a>)<br />
2.2 - Open a command prompt and CD to the folder where your extracted the source<br />
2.3 - Install lessc: <kbd>npm install lessc</kbd><br />
2.4 - Instal uglifyjs: <kbd>npm install uglify-js</kbd><br />
<b><br /></b><br />
<b>3 - Create make.bat</b><br />
Create make.bat at the root of the folder where you downloaded the source. Please note that the batch file deletes and recreates a "build" in your working folder. I know this version is not as complete as the real makefile but that is what I use now.<br />
<br />
<b><u><span style="font-size: large;">make.bat</span></u></b><br />
<br />
<div style="font-family: courier; font-size: 12px; margin-left: 10px;">
@echo off<br />
rd build /s /q<br />
mkdir build\img<br />
mkdir build\css<br />
mkdir build\js<br />
<br />
copy img\* build\img<br />
<br />
call .\node_modules\.bin\lessc -x less\bootstrap.less > build\css\bootstrap.min.css<br />
<br />
copy /B js\bootstrap-transition.js+js\bootstrap-alert.js+js\bootstrap-button.js+js\bootstrap-carousel.js+js\bootstrap-collapse.js+js\bootstrap-dropdown.js+js\bootstrap-modal.js+js\bootstrap-tooltip.js+js\bootstrap-popover.js+js\bootstrap-scrollspy.js+js\bootstrap-tab.js+js\bootstrap-typeahead.js build\js\bootstrap.js<br />
<br />
call .\node_modules\.bin\uglifyjs --ascii bootstrap\js\bootstrap.js > build\js\bootstrap.min.js</div>
<br />
<b>4 - Try it using one of the examples from the Twitter Bootstrap examples page</b><br />
<br />
4.1 - Run make.bat<br />
4.2 - Save one of the <a href="http://twitter.github.com/bootstrap/examples.html" target="_blank">twitter bootstrap examples</a> by right clicking on it and selecting "Save as link..." and save it to your source folder.<br />
4.3 - Open the example file in your favorite text editor.<br />
4.4 - Locate this line <link href="../assets/css/bootstrap.css" rel="stylesheet"> and replace it with <link href="/css/bootstrap.min.css" rel="stylesheet"><br />
4.5 - Locate this line <link href="../assets/css/bootstrap-responsive.css" rel="stylesheet"> and replace it with <link href="/css/bootstrap-responsive.min.css" rel="stylesheet"><br />
<div>
4.6 - Locate the scripts a the bottom of the file</div>
<div>
4.7 - Replace the reference to jquery with: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script></div>
<div>
4.8 - Replace all references to individual bootstrap javascript files by a single reference to bootstrap.min.js: <script src="/js/bootstrap.min.js"></script></div>
<div>
4.9 - Open the file in your Web browser.<br />
<br />
<br />
Hope this helps</div>Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com13tag:blogger.com,1999:blog-2504865884110659551.post-3524879529739964682012-05-17T00:40:00.000-04:002013-03-19T14:11:40.092-04:00Install Node on Windows with NPM tutorial<i><span style="color: blue;">This post is written for nodejs version 0.6.18. </span></i><br />
<span style="color: blue;"><i><br /></i></span>
<br />
<b>Intro:</b><br />
<br />
It took me a while to figure out a few things after installing node so this is just a few notes to help you get started.<br />
<br />
<b>Steps:</b><br />
<br />
- Download and install node from <a href="http://nodejs.org/">http://nodejs.org</a><br />
<br />
- Open a command-line in window using <i>Run As Administrator</i><br />
<br />
- make a test folder and go to that folder: <kbd>c:\node_test\</kbd><br />
<br />
- Create a hello world script: <kbd>echo console.log("Hello World") > hw.js</kbd><br />
<br />
- Run the test: <kbd>node hw.js</kbd><br />
<i><span style="color: #38761d;">Expected output: </span></i><span style="font-family: monospace;">Hello World</span><br />
<span style="color: #b45f06;"><i>Check: If you see an error here, something is wrong with your </i></span><i style="color: #b45f06;">nodejs </i><i style="color: #b45f06;">installation. Check your path maybe...</i><br />
<br />
- Enter <kbd>npm install less</kbd> to install the <b>less</b> module. It does not really matter what module you install, this just proves that the package manager called NPM works.<br />
<i><span style="color: #38761d;">Expected outcome: NPM downloading modules</span></i><br />
<span style="color: #b45f06;"><i>Check: If you see an error here, something is wrong with your nodejs installation or with NPM.</i></span><br />
<br />
- Your working directory should have a folder <b>node_modules</b> and a sub folder <b>less</b>.<br />
<i><span style="color: #b45f06;">Check: If you don't have those folders then something is wrong with where NPM installs modules.</span></i><br />
<br />
- To test the module: <kbd>node node_modules\less\bin\lessc -help</kbd> <br />
<i><span style="color: #38761d;">Expected output: a help message from less</span></i><br />
<i><span style="color: #b45f06;">Check: If you get an error, something is wrong with where or how NPM installs modules. </span></i><br />
<br />
If you got to this point without any errors, you are good to go.<br />
<br />
I hope this helps<br />
<br />
- SlySylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com7tag:blogger.com,1999:blog-2504865884110659551.post-23138417223465589412010-02-20T22:08:00.001-05:002010-02-20T22:11:36.482-05:00No configuration file with NHibernate<p><em><font color="#0000ff">Note: This post is based on NHibernate version 2.1 with Fluent NHibernate version 1.0 RTM.</font></em></p> <p>In my previous post about Fluent NHibernate, I explained how to use Fluent NHibernate to replace your <strong>NHibernate mapping files</strong> (.hbm.config) with c# code. In this post I'll show you how to also replace the  <strong>NHibernate configuation file</strong> (.cfg.xml) with code.</p> <p>This time you don't need to add references to any special library. Converting the config file to code is very, very easy. The config file is made up of a bunch of dictionary entries where each entry has a key (the NHibernate setting name) and a value (the actual value for that setting). The NHibernate has a configuration API that works the same way. So you can just take out the line that loads your config file (config.Configure("PocoLib.cfg.xml");) with a series of calls config.Properties.Add().</p> <table cellspacing="0" cellpadding="2" width="759" border="0"><tbody> <tr> <td valign="top" width="354"><strong>Before (with a .cfg.xml file)</strong></td> <td valign="top" width="403"><strong>After (with code)</strong></td> </tr> <tr> <td valign="top" width="354"> <p><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <br />  <session-factory> <br />    <property name="connection.provider"> <br />      NHibernate.Connection.DriverConnectionProvider <br />    </property> <br />    <property name="connection.driver_class"> <br />      NHibernate.Driver.SqlClientDriver <br />    </property> <br />    <property name="connection.connection_string"> <br />      Server=xp-octosql;database=PocoLib;Integrated Security=SSPI; <br />    </property> <br />    <property name="dialect"> <br />      NHibernate.Dialect.MsSql2005Dialect <br />    </property> <br />    <property name="show_sql"> <br />      true <br />    </property> <br />    <property name='proxyfactory.factory_class'> <br />      NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu <br />    </property> <br />    <property name="adonet.batch_size">16</property> <br />  </session-factory> <br /></hibernate-configuration></p> </td> <td valign="top" width="403"> <p>Configuration config = new Configuration();</p> <p>config.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider, NHibernate"); <br /> <br />config.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver"); <br /> <br />config.Properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect"); <br /> <br />config.Properties.Add("connection.connection_string", "Server=xp-octosql;database=PocoLib;Integrated Security=SSPI;");</p> <p>config.Properties.Add("show_sql", "true"); <br /> <br />config.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); <br /> <br />config.Properties.Add("adonet.batch_size", "16");</p> <p>  Fluently.Configure(configuration) <br />        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CustomerCRUDTests>()) <br />        .BuildConfiguration(); </p> <p> _factory = config.BuildSessionFactory(); </p> </td> </tr> </tbody></table> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com0tag:blogger.com,1999:blog-2504865884110659551.post-484269253836009702009-12-26T22:04:00.001-05:002009-12-26T22:05:47.307-05:00Fluent NHibernate Tutorial<p><em><font face="Times New Roman" color="#3a62a3">Note: This post is based on NHibernate version 2.1 with Fluent NHibernate version 1.0 RTM.</font></em></p> <p>This tutorial introduces Fluent NHibernate. Fluent NHibernate is a "code oriented" alternative to configuring NHibernate maping using XML configuration files.</p> <p>This tutorial is based on same project entities defined in my previous <a href="http://codethatworks.blogspot.com/2009/11/getting-started-with-nhibernate.html">NHibernate tutorial</a>. At end of this tutorial, you will have the exact same result but with entities configured using Fluent NHibernate instead of an XML configuration file.</p> <p>1. Open you the Solution PocoLib.</p> <p>2. Add a reference to FluentNHibernate in the PocoLibTests</p> <p>3. Add a new class named CustomerMap.cs to the PocoLibTests project. The source code for CustomerMap.cs is in the left column in the table below. The code speaks for itself; it's almost identical in structure to the XML configuration file.</p> <table cellspacing="0" cellpadding="2" width="687" border="1"><tbody> <tr> <td valign="top" width="427"><strong>CustomerMap.cs</strong></td> <td valign="top" width="258"><strong>Customer.hbm.xml</strong></td> </tr> <tr> <td valign="top" width="427"> <p><font face="Courier New">using FluentNHibernate.Mapping; <br />using PocoLib; </font></p> <p><font face="Courier New">namespace PocoLibTests <br />{ <br />  public class CustomerMap : ClassMap<Customer> <br />  { <br />    public CustomerMap() <br />    { <br />      Not.LazyLoad(); <br /> <br />      Id(cust => cust.ID, "CustomerID"); <br /> <br />      <br />      Map(cust => cust.FirstName); <br />      Map(cust => cust.LastName); <br />      Map(cust => cust.BirthDate); </font></p> <p><font face="Courier New">      Component<Address>(cust => cust.Address, <br />        component => <br />        { <br />          component.Map(address => address.Street); <br />          component.Map(address => address.State); <br />          component.Map(address => address.Country); <br />          component.Map(address => address.ZipCode); <br />        }); <br />    } <br />  } <br />}</font></p> </td> <td valign="top" width="258"> <p> <br /> <br /> <br /> <br /> <br /> <br /> <br /><class name="Customer" <br />        lazy="false"> <br /> <br />  <id name="ID" column="CustomerID"> <br />    <generator class="native"/> <br />  </id> <br /> <br />  <property name="FirstName"/> <br />  <property name="LastName"/> <br />  <property name="BirthDate"/> <br /> <br />  <component name="Address"> <br /> <br /> <br />    <property name="Street"/> <br />    <property name="State"/> <br />    <property name="Country"/> <br />     <property name="ZipCode"/> <br />  </component> <br /> <br /></class></p> </td> </tr> </tbody></table> <p>4. Now, open the test class. We must change the Setup method and replace the line that loads the the configuration from Customer.hbm.xml to load it using Fluent Nhibernate. </p> <p><font color="#515151">[SetUp] <br />public void Setup() <br />{ <br />    Configuration configuration = new Configuration(); <br />    configuration.Configure("PocoLib.cfg.xml");</font> </p> <p>    <strike>configuration.AddXmlFile("Customer.hbm.xml"); </strike></p> <p><font color="#000000">    Fluently.Configure(configuration) <br />        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CustomerCRUDTests>()) <br />        .BuildConfiguration(); </font></p> <p>    _factory = configuration.BuildSessionFactory(); <br />}</p> <p>5. Delete the Customer.hbm.xml file from the PocoLib project and from the /debug/bin/ folder of the PocoLibTests project.</p> <p>6. You can now run the tests tests.</p> <p>That's it for this quick Fluent NHibernate tutorial.</p> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com2tag:blogger.com,1999:blog-2504865884110659551.post-65461758695086385192009-11-08T21:19:00.001-05:002009-11-08T21:20:06.711-05:00LINQ to NHibernate Tutorial<p><em><font face="Times New Roman" color="#3a62a3">Note: This post applies to NHibernate 2.1 with LINQ to NHibernate version 1.0.</font></em></p> <p>Starting with LINQ to NHibernate is really simple; you just have to add a reference to NHibernate.Linq.dll to your host project (a test project, an ASP.NET app).</p> <p>Here is a unit test to demonstrate a simple LINQ query.  This test uses the same entities defined in my previous <a href="http://codethatworks.blogspot.com/2009/11/getting-started-with-nhibernate.html">NHibernate tutorial</a>.</p> <blockquote> <p><font face="Courier New">[Test] <br />public void SelectWithPredicate() <br />{ <br />    using (var session = _factory.OpenSession()) <br />    { <br />        //Act <br />        var customers = from cust in <strong><font color="#000080">session.Linq<Customer>()</font></strong> <br />                        where cust.LastName.StartsWith("St") <br />                        select cust; <br />        //Assert <br />        Assert.AreEqual(1, customers.Count()); <br />    } <br />}</font></p> </blockquote> <p>The Linq() method is an extension method defined in NHibernate.Linq.dll. It provides the entry point to execute Linq queries on your NHibernate entities. When you run that test, NHibernate generates the following statement:</p> <blockquote> <p><font face="Courier New">SELECT count(*) as y0_ FROM Customer this_ <br />WHERE this_.LastName like @p0;@p0 = 'St%'</font></p> </blockquote> <p> In an upcoming post I will explore the capabilities and limitations of LINQ to NHibernate. For now, here is the full test class I used to discover LINQ to NHibernate:</p> <blockquote> <p><font face="Courier New">using System.Diagnostics; <br />using System.Linq; <br />using NHibernate; <br />using NHibernate.Cfg; <br />using NHibernate.Linq; <br />using NUnit.Framework; <br />using PocoLib; </font></p> <p><font face="Courier New">namespace PocoLibTests <br />{ <br />    [TestFixture] <br />    public class CustomerLINQTests <br />    { <br />        private ISessionFactory _factory; </font></p> <p><font face="Courier New">        [SetUp] <br />        public void Setup() <br />        { <br />            Configuration configuration = new Configuration(); <br />            configuration.Configure("PocoLib.cfg.xml"); <br />            configuration.AddXmlFile("Customer.hbm.xml"); </font></p> <p><font face="Courier New">            _factory = configuration.BuildSessionFactory(); </font></p> <p><font face="Courier New">            SetupDatabase(); <br />        } </font></p> <p><font face="Courier New">        [TearDown] <br />        public void TearDown() <br />        { <br />            PurgeDatabase(); <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void SelectAllCustomers() <br />        { <br />            using (var session = _factory.OpenSession()) <br />            { <br />                //Act <br />                var customers = from cust in session.Linq<Customer>() <br />                                select cust; <br />                //Assert <br />                Assert.AreNotEqual(4, customers.Count()); <br />            } <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void SelectWithPredicate() <br />        { <br />            using (var session = _factory.OpenSession()) <br />            { <br />                //Act <br />                var customers = from cust in session.Linq<Customer>() <br />                                where cust.LastName.StartsWith("St") <br />                                select cust; <br />                //Assert <br />                Assert.AreEqual(1, customers.Count()); <br />            } <br />        } </font></p> <p><font face="Courier New">        private void SetupDatabase() <br />        { <br />            using (var session = _factory.OpenSession()) <br />            { <br />                Customer c = new Customer(); <br />                c.FirstName = "Mike"; <br />                c.LastName = "Laroco"; <br />                c.Address.Country = "USA"; <br />                session.SaveOrUpdate(c); </font></p> <p><font face="Courier New">                c = new Customer(); <br />                c.FirstName = "Bubba"; <br />                c.LastName = "Stuart"; <br />                c.Address.Country = "USA"; <br />                c.Address.State = "Florida"; <br />                session.SaveOrUpdate(c); </font></p> <p><font face="Courier New">                c = new Customer(); <br />                c.FirstName = "Ricky"; <br />                c.LastName = "Carmichael"; <br />                c.Address.Country = "USA"; <br />                c.Address.State = "Florida"; <br />                session.SaveOrUpdate(c); </font></p> <p><font face="Courier New">                c = new Customer(); <br />                c.FirstName = "Jean-Sebastien"; <br />                c.LastName = "Roy"; <br />                c.Address.Country = "Canada"; <br />                c.Address.State = "Quebec"; <br />                session.SaveOrUpdate(c); </font></p> <p><font face="Courier New">                session.Flush(); <br />            } </font></p> <p><font face="Courier New">            Debug.WriteLine("end prepare data"); </font></p> <p><font face="Courier New">        } </font></p> <p><font face="Courier New">        private void PurgeDatabase() <br />        { <br />            using (var session = _factory.OpenSession()) <br />            { <br />                session.Delete("from Customer"); <br />                session.Flush(); <br />            } <br />        } </font></p> <p><font face="Courier New">    } <br />}</font></p> </blockquote> <p> Thanks</p> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com3tag:blogger.com,1999:blog-2504865884110659551.post-37599125314260110532009-11-05T23:59:00.002-05:002009-11-14T11:50:44.924-05:00NHibernate Tutorial<p><em><font face="Times New Roman" color="#3a62a3">Note: This post is based on NHibernate version 2.1.</font></em></p> <p>This is a tutorial to get you started with NHibernate.</p> <p>At the end of this tutorial you will have:</p> <ul> <li>A class library project containing one entity </li> <li>A NHibernate configuration file </li> <li>A NHibernate mapping file to map your entities </li> <li>A database running on SQL Server 2005 (changing to another version of SQL server is very simple) </li> <li>A NUnit test project </li> </ul> <p>1 - Create a new class library project named PocoLib in a new solution. This project will contain your entity classes.</p> <p>2 - In the same solution, create a new class library project called PocoLibTests</p> <p>3 - In the PocoLibTests project add references to </p> <ul> <li>PocoLib project </li> <li>nunit.framework.dll </li> <li>nhibernate.dll </li> <li>LinFu.DynamicProxy </li> <li>NHibernate.ByteCode.LinFu </li> </ul> <p><em>Note: You do not have to add any references to nhibernate dlls in the PocoLib project. Your entity classes will not have any knowledge of NHibernate; they are real POCO. If you eventually use your entities in a Web app or Web Services project (most likely), it will be that app that will need those same references (except for Nunit of course).</em></p> <p>4 - In PocoLibTests, rename class1.cs to CustomerCRUDTests.cs to your project.</p> <blockquote> <p><font face="Courier New">using NHibernate; <br />using NHibernate.Cfg; <br />using NUnit.Framework; <br />using PocoLib; </font></p> <p><font face="Courier New">namespace PocoLibTests <br />{ <br />    [TestFixture] <br />    public class CustomerCRUDTests <br />    { </font></p> <p><font face="Courier New">        [Test] <br />        public void Insert() <br />        { <br />            Customer c = new Customer() <br />                { FirstName = "Bubba", LastName = "Stuart" }; </font></p> <p><font face="Courier New">            c.Address.Country = "USA"; <br />            c.Address.State = "Florida"; </font></p> <p><font face="Courier New">            using (ISession session = _factory.OpenSession()) <br />            { <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } <br />        } <br />    } <br />}</font></p> <p><font face="Courier New"></font></p> </blockquote> <p>This test does not compile for now but that gives you an idea of what we are going to work with.</p> <p>5 - In the PocoLib project rename class1.cs to Address.cs:</p> <blockquote> <p><font face="Courier New">namespace PocoLib <br />{ <br />    public class Address <br />    { <br />        private string _zipCode; <br />        private string _country; <br />        private string _state; <br />        private string _street; </font></p> <p><font face="Courier New">        public string Street <br />        { <br />            get { return _street; } <br />            set { _street = value; } <br />        } </font></p> <p><font face="Courier New">        public string State <br />        { <br />            get { return _state; } <br />            set { _state = value; } <br />        } </font></p> <p><font face="Courier New">        public string Country <br />        { <br />            get { return _country; } <br />            set { _country = value; } <br />        } </font></p> <p><font face="Courier New">        public string ZipCode <br />        { <br />            get { return _zipCode; } <br />            set { _zipCode = value; } <br />        } <br />    } <br />}</font></p> </blockquote> <p>6 - In the PocoLib project add a new class named Customer.cs:</p> <blockquote> <p><font face="Courier New">using System; <br />using System.Collections.Generic; </font></p> <p><font face="Courier New">namespace PocoLib <br />{ <br />    public class Customer <br />    { <br />        private int _iD; <br />        private DateTime? _birthDate; <br />        private string _lastName; <br />        private string _firstName; <br />        private Address _address = new Address(); <br /></font><font face="Courier New"></font></p> <p><font face="Courier New">        public int ID <br />        { <br />            get { return _iD; } <br />            set { _iD = value; } <br />        } </font></p> <p><font face="Courier New">        public string FirstName <br />        { <br />            get { return _firstName; } <br />            set { _firstName = value; } <br />        } </font></p> <p><font face="Courier New">        public string LastName <br />        { <br />            get { return _lastName; } <br />            set { _lastName = value; } <br />        } </font></p> <p><font face="Courier New">        public DateTime? BirthDate <br />        { <br />            get { return _birthDate; } <br />            set { _birthDate = value; } <br />        } </font></p> <p><font face="Courier New">        public Address Address <br />        { <br />            get { return _address; } <br />            set { _address = value; } <br />        } </font></p> <p><font face="Courier New">    } <br />}</font></p> </blockquote> <p>As you can see, the model is simple: a customer has a few properties and an Address. </p> <p>Note: At this point, the test project still does not compile because the _factory is not defined yet. We will define it really soon.</p> <p>7 - Create a new database with a Customer table</p> <blockquote> <p><font face="Courier New">CREATE DATABASE PocoLib <br />GO </font></p> <p><font face="Courier New">USE PocoLib <br />GO </font></p> <p><font face="Courier New">CREATE TABLE [dbo].[Customer]( <br />[CustomerID] [int] IDENTITY(1,1) NOT NULL, <br />[FirstName] [varchar](50) NULL, <br />[LastName] [varchar](50) NOT NULL, <br />[BirthDate] [datetime] NULL, <br />[Street] [varchar](50) NULL, <br />[State] [varchar](50) NULL, <br />[Country] [varchar](50) NULL, <br />[ZipCode] [varchar](50) NULL) <br />GO</font> </p> <p><font face="Courier New"></font></p> </blockquote> <p>Notice how we are using two classes (Customer and Address) but a single Customer table. It is much cleaner to use two classes at the class design level. But since it is a one-to-one relationship, saving the address in the same table as customer makes total sense (it's simpler, faster and feel more natural).</p> <p>8 - In the PocoLib project, add an xml file named PocoLib.cfg.xml. That will be your main NHibernate configuration file. It's arguable whether this file belongs to the PocoLib class library or to the host application (the test project in this case), but for now let's put it in PocoLib.</p> <blockquote> <p><font face="Courier New"><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <br />  <session-factory> <br />    <property name="connection.provider"> <br />      NHibernate.Connection.DriverConnectionProvider <br />    </property> <br />    <property name="connection.driver_class"> <br />      NHibernate.Driver.SqlClientDriver <br />    </property> <br />    <property name="connection.connection_string"> <br />      Server=<strong>localhost</strong>;database=<strong>PocoLib</strong>;Integrated Security=SSPI; <br />    </property> <br />    <property name="dialect"> <br />      NHibernate.Dialect.MsSql2005Dialect <br />    </property> <br />    <property name="show_sql"> <br />      true <br />    </property> <br />    <property name='proxyfactory.factory_class'> <br />      NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu <br />    </property>  <br />  </session-factory> <br /></hibernate-configuration></font></p> </blockquote> <ul> <li>Change the connection string (line 10) if needed. </li> <li>If you are not on SQL Server 2005, you can change the other settings. For instance, set the dialect setting to Nibernate.Dialect.MsSql2008Dialect if your on SQL Server 2008. </li> </ul> <p>9 - In the PocoLib project, add an xml file named Customer.hbm.xml. That will be mapping file used to tell NHibernate where to persist and load our entities. (The same question about where this file should reside applies here too).</p> <blockquote> <p><font face="Courier New"><?xml version="1.0" encoding="utf-8" ?> <br /><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" <br />                   assembly="PocoLib" <br />                   namespace="PocoLib"> </font></p> <p><font face="Courier New">  <class name="Customer" lazy="false"> <br />    <id name="ID" column="CustomerID"> <br />      <generator class="native"/> <br />    </id> <br />    <property name="FirstName"/> <br />    <property name="LastName"/> <br />    <property name="BirthDate"/> <br />    <component name="Address"> <br />      <property name="Street"/> <br />      <property name="State"/> <br />      <property name="Country"/> <br />      <property name="ZipCode"/> <br />    </component>  <br />  </class> <br /></hibernate-mapping></font></p> </blockquote> <p>I think the content of the file pretty much speaks for itself but here are a few things worth mentioning:</p> <ul> <li>By default, NHibernate assumes that your database column names match your class property names. </li> <li>The <id> element identifies the primary key column. The <generator class="native"> indicates that SQL Server will generate the primary key value; not NHibernate. </li> <li>The Customer is defined as a <class> in the mapping. This is what NHibernate calls an <u>entity</u>. </li> <li>The Address is declared inside the Customer as an<component> element. That basically means that the Address is a part of the Customer and it can't live without a customer. NHibernate components are also know as Value Object in Domain Driven Design. </li> </ul> <p>10 - Copy the PocoLib.cfg.xml and Customer.hbm.xml to the test library \bin\debug\ folder.</p> <p>11 - Add the missing _factory to the test class. Add this code at the top of the test class:</p> <blockquote> <p><font face="Courier New">        private ISessionFactory _factory; </font></p> <p><font face="Courier New">        [SetUp] <br />        public void Setup() <br />        { <br />            Configuration configuration = new Configuration(); <br />            configuration.Configure("PocoLib.cfg.xml"); <br />            configuration.AddXmlFile("Customer.hbm.xml"); </font></p> <p><font face="Courier New">            _factory = configuration.BuildSessionFactory(); <br />        }</font></p> </blockquote> <ul> <li>The first line create a Configuration object. </li> <li>The second line loads the PocoLib.cfg.xml. </li> <li>The 3rd line loads the mapping file for the Customer class. </li> <li>The 4th line create a factory that we will use to create NHibernate Sessions (a connection) </li> </ul> <p>13 - Run the <font face="Courier New">Insert()</font> test. Go look in the database and be amazed (or not). Notice how SQL statements are written to the output window (If you are using Test Driven at least). You can turn that on or off by changing the <property name="show_sql">true</property> in the .cfg.xml file.</p> <p>12 - Here are the other CRUD tests. I'm sorry but I don't feel like writing all the Asserts; this is just a test project to experiment with the CRUD operations.</p> <blockquote> <p><font face="Courier New">using System.Collections.Generic; <br />using NHibernate; <br />using NHibernate.Cfg; <br />using NUnit.Framework; <br />using PocoLib; </font></p> <p><font face="Courier New">namespace PocoLibTests <br />{ <br />    [TestFixture] <br />    public class CustomerCRUDTests <br />    { <br />        private ISessionFactory _factory; </font></p> <p><font face="Courier New">        [SetUp] <br />        public void Setup() <br />        { <br />            Configuration configuration = new Configuration(); <br />            configuration.Configure("PocoLib.cfg.xml"); <br />            configuration.AddXmlFile("Customer.hbm.xml"); </font></p> <p><font face="Courier New">            _factory = configuration.BuildSessionFactory(); <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void Insert() <br />        { <br />            Customer c = new Customer() <br />               { FirstName = "Bubba", LastName = "Stuart" }; </font></p> <p><font face="Courier New">            c.Address.Country = "USA"; <br />            c.Address.State = "Florida"; </font></p> <p><font face="Courier New">            using (ISession session = _factory.OpenSession()) <br />            { <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void Update() <br />        { <br />            // Arrange : Create customer in order to update it <br />            Customer c = new Customer()  <br />                { FirstName = "Bubba", LastName = "Stuart" }; <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } <br />            int id = c.ID; </font></p> <p><font face="Courier New">            //Act : update <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                c = session.Get<Customer>(id); <br />                c.FirstName = "James"; <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void Delete() <br />        { <br />            // Arrange : Create customer in order to delete it <br />            Customer c = new Customer() <br />                { FirstName = "Bubba", LastName = "Stuart" }; <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } <br />            int id = c.ID; </font></p> <p><font face="Courier New">            //Act : Delete <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                c = session.Get<Customer>(id); <br />                session.Delete(c); <br />                session.Flush(); <br />            } <br />        } </font></p> <p><font face="Courier New">        [Test] <br />        public void Query() <br />        { <br />            // Arrange : Create a customer in order to query it <br />            Customer c = new Customer()  <br />                 { FirstName = "Bubba", LastName = "Stuart" }; <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                session.SaveOrUpdate(c); <br />                session.Flush(); <br />            } </font></p> <p><font face="Courier New">            IList<Customer> list = null; </font></p> <p><font face="Courier New">            //Act: <br />            using (ISession session = _factory.OpenSession()) <br />            { <br />                list = session.CreateQuery( <br />                   "from Customer where LastName is not null") <br />                   </font><font face="Courier New">.List<Customer>(); <br />            } </font></p> <p><font face="Courier New">            //Assert: <br />            Assert.AreNotEqual(0, list.Count); </font></p> <p><font face="Courier New">        } </font></p> <p><font face="Courier New">    } <br />}</font></p> </blockquote> <p>I hope this helps.</p> <p>BTW: I started learning NHibernate just a few days ago. I'm wrote this post to serialize what I have learned so far (and hopefully help people at the same time). I'm sure this approach is not ideal. If you have comments on how I could improve this tutorial, just let me know. </p> <p>Thanks </p>Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com5tag:blogger.com,1999:blog-2504865884110659551.post-61607878178449537712009-11-01T12:21:00.001-05:002009-11-01T12:21:46.547-05:00Monotouch debugger now avaliable<p>This very short post is simply to announce that monotouch now has a debugger (breakpoints, watch) that works on the device and in the simulator.</p> <p>Kudos to the monotouch team!</p> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com0tag:blogger.com,1999:blog-2504865884110659551.post-2486844142404222732009-11-01T12:17:00.002-05:002009-11-01T12:48:10.940-05:00jQuery plug-in to fix the width=100% problem<p>While making the layout for a new app I’m writing, I discovered what I call the <strong><em>Box model 100% width bug</em></strong>.</p> <p>The box model spec states that the resulting width of an element whose width is 100% will equal to:</p> <blockquote> <p>calculated width = (inner width of parent) + (element's padding) + (element's margin)</p> </blockquote> <p>That means that given this html:</p> <blockquote> <p><font face="Courier New"><div id="container" style="width:400px;"> <br />  <div id="div1"  <br />     style="background-color:Green; width:100%; margin-left:10px; padding-left:10px;"> <br />     Lorem ipsum dolor sit amet, consectetur adipisicing elit... <br />  </div> <br /></container></font></p> </blockquote> <p>The div1 's total width will be <strong>420px</strong>; not <strong>400px </strong>as you would want. </p> <p>A solution is to compensate by wrapping div1 in a container that has a padding-left equal to the element's (2 * margin) + (padding):</p> <blockquote> <p><font face="Courier New"><div id="container" style="width:400px;"> <br />  <div id="wrapper" style="padding-left:30px;"> <br />    <div id="div1"  <br />     style="background-color:Green; width:100%; margin-left:10px; padding-left:10px;"> <br />     Lorem ipsum dolor sit amet, consectetur adipisicing elit... <br />    </div> <br />  </div> <br /></container></font></p> </blockquote> <p>Why add an extra element instead of modifying the container div? Because in a real cases, the container div will probably be many levels above the element that you are trying to style. The wrapper div used to compensate should be the immediate parent of that element.</p> <p>I wrote a jQuery plugin to automatically inject the wrapper div to elements. Here is how to use it:</p> <blockquote> <p><font face="Courier New">$(function() { <br />    $("#div1").fixFullWidth(); <br />})</font></p> </blockquote> <p>The plug-in iterates  through at all elements selected by the jQuery selector and wraps each of them in a div that has the correct padding-left value.</p> <p>Here is the plug-in source. BTW, I'm not a javascript expert so if you come up with a better implementation just let me know and I will update this post.</p> <blockquote> <p><font face="Courier New">$.fn.fixFullWidth = function() { <br /></font><font face="Courier New">    //create the endsWith function of the String type <br />    String.prototype.endsWith = function(str) { <br /></font><font face="Courier New">        return (this.match(str + "$") == str); <br /></font><font face="Courier New">    } <br /></font><font face="Courier New"> <br />   this.each(function() { <br /></font><font face="Courier New">        var elemMarginValue = $(this).css('margin-left'); <br /></font><font face="Courier New">        var elemMargin = 0; <br /></font><font face="Courier New">        if (elemMarginValue.endsWith("px")) { <br /></font><font face="Courier New">            elemMargin = parseInt( elemMarginValue.replace('px', '')); <br /></font><font face="Courier New">        } <br /></font><font face="Courier New">        var elemPaddingValue = $(this).css('padding-left'); <br /></font><font face="Courier New">        var elemPadding = 0; <br /></font><font face="Courier New">        if (elemPaddingValue.endsWith("px")) { <br /></font><font face="Courier New">            elemPadding = parseInt( elemPaddingValue.replace('px', '')); <br /></font><font face="Courier New">        } <br /></font><font face="Courier New">        var padding_left = (elemMargin * 2) + elemPadding; <br /></font><font face="Courier New">        if (padding_left != 0) { <br /></font><font face="Courier New">            $(this).wrap('<div class="fixFullWidth" style="padding-right:' + padding_left + 'px;"></div>'); <br /></font><font face="Courier New">        } <br /></font><font face="Courier New">    }); <br /></font><font face="Courier New">    return this; <br /></font><font face="Courier New">};</font></p> <p></p> </blockquote> <p>I hope this helps. </p> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com1tag:blogger.com,1999:blog-2504865884110659551.post-8553069814681855562009-10-03T14:14:00.008-04:002009-10-03T23:46:54.761-04:00How to fix MonoDevelop code completion problem?At the time of this post, there is a known issue with MonoDevelop's Code Completions feature. At some point, code completion stops working and you get "Gathering class information..." in the code completion drop down list.<br /><br />Before you apply this workaround, ensure that you have the latest build of MonoDevelop.<br /><br /><span style="font-weight: bold;">Workaround: Manually clear the code completion cache</span><br /><br />On a Mac:<br /><br /><ul><li>Close MonoDevelop </li><li>Open the Terminal application</li><li>Run this command: <code>rm -r ~/.config/MonoDevelop/CodeCompletionData</code></li><li>Restart MonoDevelop </li></ul>Note: For some reason, it did not work on my first attempt. MonoDevelop was still "Gathering class information", I listed the content of the CodeCompletionData folder and no files would appear. I did the same procedure again and it worked. So you might have to do this more than once.<br /><br />I hope this helps.<br /><br />Thanks to @mikebluestein and @mikrueger on twitter for their help.Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com1tag:blogger.com,1999:blog-2504865884110659551.post-42557441984972904512009-09-29T12:37:00.011-04:002009-10-03T14:49:45.351-04:00iPhone programming in C# with MonoTouchTwo weeks ago Novell released MonoTouch (www.monotouch.net), a SDK to develop in .Net for the iPhone.<br /><br />I started programming with MonoTouch two days ago. So far I must say I'm impressed. I had absolutely no experience on a Mac before.<br /><br /><br />Here is a summary of the experience with MonoTouch:<br /><br />- You need a Mac on which you install:<br /><br /><ul><li> iPhone SDK from Apple (iPhone Library and Interface Builder)</li><li> Mono Framework</li><li> MonoDevelop IDE</li><li> MonoTouch SDK</li></ul><br />- You create user interfaces using Interface Builder, the standard User Interface designer program for Mac/iPhone apps that is part of the SDK.<br /><br /><br />- You code your logic in C# using an IDE called MonoDevelop which is somewhat similar to Visual Studio and includes code completion. You have access to the C# 3.0 (LINQ, Lambda, Generics) features, Garbage Collection (not offered in the native iPhone SDK) and most general purpose .net APIs. They have wrapped a large portion of the iPhone SDK with a C# friendly API style.<br /><br /><br />Overall, the experience is quite good. There is one important issue though; there is no debugger (no breakpoints, no watch window, no call stack). You must debug using Console.WriteLine(). I hope Novell will find a way to debug in an upcoming release.<br /><br /><br />-SlySylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com0tag:blogger.com,1999:blog-2504865884110659551.post-73482552514096835332008-11-28T19:08:00.004-05:002009-11-01T12:37:52.798-05:00Unity Application Block Tutorial<p>This article explains how to get started with the Unity Application Block using a simple console application. Throughout this tutorial you will learn how to configure and use the "Inversion of Control" and "Dependency Injection" features of the Unity Application Block.</p> <p><strong>Assumptions</strong></p> <p>This article assumes that:</p> <p>You know what DIP, IoC and DI are. <br />You want to configure your type mappings using a configuration file; not using code.</p> <p><strong>Container</strong></p> <p>The "Container" or "Inversion of Control Container" is the main object that is used to create objects and inject dependencies into them. Whenever you want an object to be open to IoC, you have to use the container to create the instance using container.Resolve<T>() method instead of the "new" keyword. </p> <p><font face="Courier New">IService service = unityContainer.Resolve< IService>();</font></p> <p>Create the project and add references to the required assemblies</p> <ul> <li>Create a new console project called UnityTest (if you use another name, you will have to change type names in configuration files so I recommend you stick to this name).</li> <li>Add references to the following assemblies:</li> <ul> <li>System.Configuration</li> <li>Microsoft.Practices.ObjectBuilder2</li> <li>Microsoft.Practices.Unity</li> <li>Microsoft.Practices.Unity.Configuration</li> </ul> </ul> <p>Create the application configuration file</p> <ul> <li>Add App.config configuration file to your project</li> <li>Enter the following code in the App.config file</li> </ul> <blockquote> <p><font face="Courier New"><?xml version="1.0" encoding="utf-8" ?> </font></p> <p><font face="Courier New"><configuration> </font></p> <p><font face="Courier New">    <configSections> </font></p> <p><font face="Courier New">        <section</font></p> <p><font face="Courier New">            name="unity"</font></p> <p><font face="Courier New">            type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, </font></p> <p><font face="Courier New">            Microsoft.Practices.Unity.Configuration" /> </font></p> <p><font face="Courier New">    </configSections> </font></p> <p><font face="Courier New"><unity> </font></p> <p><font face="Courier New">    <containers> </font></p> <p><font face="Courier New">    <container> </font></p> <p><font face="Courier New">    <types> </font></p> <p><font face="Courier New">    </types> </font></p> <p><font face="Courier New">    </container> </font></p> <p><font face="Courier New">    </containers> </font></p> <p><font face="Courier New"></unity> </font></p> <p><font face="Courier New"></configuration></font> </p> </blockquote> <p>This is the smallest working configuration file you can have for Unity to work. There is one configSections element that describes how .Net should read the upcoming section. <br />There is one, empty, container configuration nested in a containers, nested in a sections called "unity". With this configuration, your will be able to create and configure the container object and then use the container to create objects.</p> <p><strong>Create and configure the UnityContainer instance</strong></p> <p>In your project's Main() method, add the following code to create a container instance and configure it by reading the "unity" configuration section defined in the app.config file.</p> <blockquote> <p><font face="Courier New">static void Main(string[] args) </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    IUnityContainer container = new UnityContainer(); </font></p> <p><font face="Courier New">    UnityConfigurationSection section = </font></p> <p><font face="Courier New">    (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); </font></p> <p><font face="Courier New">    section.Containers.Default.Configure(container); </font></p> <p><font face="Courier New">}</font> </p> </blockquote> <p>That's it. You can now create instances using container.Resolve<T>() for any type. As you will see, the container is able to Resolve any type, even if no type mapping exist in the configuration file. If you give it a concrete type, it will simply create an instance of that type and return it to you. You can later add a type mapping for that type and the real IoC benefits will be introduced automatically.</p> <p><strong>Create an instance and inject dependencies</strong></p> <p>Add these 3 types to your project. </p> <blockquote> <p><font face="Courier New">public class InvoiceManager </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    private IInvoicingService _invoicingService; </font></p> <p><font face="Courier New">    public InvoiceManager(IInvoicingService invoicingService) </font></p> <p><font face="Courier New">    { </font></p> <p><font face="Courier New">        _invoicingService = invoicingService; </font></p> <p><font face="Courier New">    } </font></p> <p><font face="Courier New">    public void Manage() </font></p> <p><font face="Courier New">    { </font></p> <p><font face="Courier New">        Console.WriteLine(_invoicingService.GetCount()); </font></p> <p><font face="Courier New">    } </font></p> <p><font face="Courier New">    } </font></p> <p><font face="Courier New">    public interface IInvoicingService </font></p> <p><font face="Courier New">    { </font></p> <p><font face="Courier New">        </font><font face="Courier New">string GetCount(); </font></p> <p><font face="Courier New">    </font><font face="Courier New">} </font></p> <p><font face="Courier New">    </font><font face="Courier New">public class InvoicingService : IInvoicingService </font></p> <p><font face="Courier New">    </font><font face="Courier New">{ </font></p> <p><font face="Courier New">    </font><font face="Courier New">public InvoicingService() </font></p> <p><font face="Courier New">    </font><font face="Courier New">{ </font></p> <p><font face="Courier New">    </font><font face="Courier New">} </font></p> <p><font face="Courier New">    </font><font face="Courier New">public string GetCount() </font></p> <p><font face="Courier New">    </font><font face="Courier New">{ </font></p> <p><font face="Courier New">        </font><font face="Courier New">return DateTime.Now.ToString(); </font></p> <p><font face="Courier New">    } </font></p> <p><font face="Courier New">} </font></p> </blockquote> <p>Take a minute to study the dependencies: An InvoiceManager uses (depends on) an IInvoiceService. The class InvoicingService it the concrete implementation for IInvoiceService.</p> <p>Add a type mapping in the App.config file. Change the content of the <unity> section this way:</p> <blockquote> <p><font face="Courier New"><containers> </font></p> <p><font face="Courier New"><container> </font></p> <p><font face="Courier New">    <types> </font></p> <p><font face="Courier New">        <type type ="UnityTest.IInvoicingService, UnityTest" </font></p> <p><font face="Courier New">              mapTo="UnityTest.InvoicingService, UnityTest"> </font></p> <p><font face="Courier New">        </type> </font></p> <p><font face="Courier New">    </types> </font></p> <p><font face="Courier New"></container> </font></p> <p><font face="Courier New"></containers></font> </p> </blockquote> <p>- Append these lines to your Main() function without changing the existing lines that create and configure the container. </p> <blockquote> <p><font face="Courier New">IInvoicingService service = container.Resolve<IInvoicingService>(); </font></p> <p><font face="Courier New">console.WriteLine( service.GetCount()); </font></p> </blockquote> <p>- Run the project and see the result. </p> <p>The container returns an InvoiceService when asked to resolve the type IInvoiceService. </p> <p>- Delete the two new lines and replace them by the following two lines:</p> <blockquote> <p><font face="Courier New">InvoiceManager manager = container.Resolve<InvoiceManager>(); </font></p> <p><font face="Courier New">manager.Manage();</font> </p> </blockquote> <p>- Run the project and see the result. </p> <p>Although the InvoiceManager class is not configured in the App.config file, it is still participating in Dependency Injection. When asked to resolve the type InvoiceManager, the UnityContainer did not find any mapping to use to substitute InvoiceManager by something else. However, the UnityContainer analyzed the constructor of InvoiceManager and found that InvoiceManager has a dependency on IInvoicingService. So the UnityContainer resolved IInvoicingService into an InvoiceService and then passed it to the InvoiceManager constructor.</p> <p>If you are curious, add breakpoints to the InvoiceService and InvoiceManager constructors and run the program. Notice in which order objects are created. Have a look at the call stack windows just to have an idea of what is happening under the hood.</p> <p><strong>Lifetime management</strong></p> <p>The UnityContainer is able to manage the lifetime of the objects it resolves. By default, the UnityContainer creates a new instance of any type it resolves. You can prove this with this unit test:</p> <blockquote> <p><font face="Courier New">IInvoicingService service1 = container.Resolve<IInvoicingService>(); </font></p> <p><font face="Courier New">IInvoicingService service2 = container.Resolve<IInvoicingService>(); </font></p> <p><font face="Courier New">Assert.AreNotSame( service1, service2 );</font> </p> </blockquote> <p>There are 4 basic options for lifetime management:</p> <p>No management: The container does not keep a reference on the objects it creates and therefore creates a new object each time Resolve<T>() is called. <br />Singleton: The container always returns the same instance <br />Singleton-per-thread: The container keeps one instance for each thread and return the instance based on the current thread. <br />Externally controlled: You provide a class that will manage the instances. This option is not covered in this article.</p> <p><u>Lifetime management configuration</u></p> <p>The configuration of lifetime management is done at the <type> level. Each lifetime management option is supported by one type (class) in the unity application block library. </p> <p>For example, the class ContainerControlledLifetimeManager is the class that implements the "singleton" lifetime management style. </p> <p>- To resolve the IInvoicingService type using a singleton, change the <type> section this way:</p> <blockquote> <p><font face="Courier New"><type type="UnityTest.IInvoicingService, UnityTest" </font></p> <p><font face="Courier New">      mapTo="UnityTest.InvoicingService, UnityTest"> </font></p> <p><font face="Courier New"><lifetime type= "Microsoft.Practices.Unity.ContainerControlledLifetimeManager, </font></p> <p><font face="Courier New">Microsoft.Practices.Unity" /> </font></p> <p><font face="Courier New"></type></font></p> </blockquote> <p><u>Lifetime management using aliases</u></p> <p>Using the fully qualified name for the ContainerControlledLifetimeManager class can make files hard to read. The configuration section for unity supports defining aliases. The aliases can then be used anywhere a type name is expected. I recommend defining 3 aliases for the 3 types of lifetime management option.</p> <p>- Inside the <unity> section (but above and outside the <containers> sections, add the following alias definitions:</p> <blockquote> <p><font face="Courier New"><typeAliases> </font></p> <p><font face="Courier New">    <typeAlias alias="singleton" </font></p> <p><font face="Courier New">        type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, </font><font face="Courier New">Microsoft.Practices.Unity" /> </font></p> <p><font face="Courier New"></font></p> <p><font face="Courier New">    <typeAlias alias="perThread" </font></p> <p><font face="Courier New">        type="Microsoft.Practices.Unity.PerThreadLifetimeManager, </font><font face="Courier New">Microsoft.Practices.Unity" /> </font></p> <p><font face="Courier New"></font></p> <p><font face="Courier New">    <typeAlias alias="external" </font></p> <p><font face="Courier New">        type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, </font><font face="Courier New">Microsoft.Practices.Unity" /> </font></p> <p><font face="Courier New"></font></p> <p><font face="Courier New"></typeAliases></font> </p> </blockquote> <p>- You can now simplify the <type> declaration for IInvoicingService this way:</p> <blockquote> <p><font face="Courier New"><type type="UnityTest.IInvoicingService, UnityTest" </font></p> <p><font face="Courier New">    mapTo="UnityTest.InvoicingService, UnityTest"> </font></p> <p><font face="Courier New">    <lifetime type="singleton" /> </font></p> <p><font face="Courier New"></type></font></p> </blockquote> <p>Tip: You can also define aliases the same way for your own types if you would like to simplify the type mapping for your own type.</p> <p>Tip: You can also specify a lifetime for type that does not have a mapping. In this case, add a <type> section for that type but do not add a mapTo attribute. Then add the <lifetime> element to that type.</p> <p><strong>Other methods for injecting dependencies</strong></p> <p>So far, we have seen that the UnityContainer can inject dependencies by analyzing the constructor of a type and passing the necessary dependencies to it. In this section, we will see how dependencies can be injected using other mechanisms.</p> <p><u>Dependency injection by property assignment</u></p> <p>- Add these two classes to your project:</p> <blockquote> <p><font face="Courier New">public interface ICustomerService </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    string GetCustomer(); </font></p> <p><font face="Courier New">} </font></p> <p><font face="Courier New">public class CustomerService : ICustomerService </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    public string GetCustomer() </font></p> <p><font face="Courier New">    { </font></p> <p><font face="Courier New">        return "Sylvain Hamel"; </font></p> <p><font face="Courier New">    } </font></p> <p><font face="Courier New">}</font></p> </blockquote> <p>- Add the following type mapping into the configuration file:</p> <blockquote> <p><font face="Courier New"><type type="UnityTest.ICustomerService, UnityTest" </font></p> <p><font face="Courier New">      mapTo="UnityTest.CustomerService, UnityTest"> </font></p> <p><font face="Courier New">    <lifetime type="singleton" /> </font></p> <p><font face="Courier New"></type> </font></p> </blockquote> <p>- Change the InvoiceManager by adding a new Property of type ICustomerService:</p> <blockquote> <p><font face="Courier New">private ICustomerService _customerService; </font></p> <p><font face="Courier New">[Dependency] </font></p> <p><font face="Courier New">public ICustomerService CustomerService </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    get { return _customerService; } </font></p> <p><font face="Courier New">    set { _customerService = value; } </font></p> <p><font face="Courier New">}</font> </p> </blockquote> <p>Notice the use of the [Dependency] attribute. This will indicate to the UnityContainer that a dependency injection is required here.</p> <p>- Change the Manage() method of the InvoiceManager this way</p> <blockquote> <p><font face="courier ">public void Manage() </font></p> <p><font face="courier ">{ </font></p> <p><font face="courier ">    Console.WriteLine(_invoicingService.GetCount()); </font></p> <p><font face="courier ">    Console.WriteLine(_customerService.GetCustomer()); </font></p> <p><font face="courier ">} </font></p> </blockquote> <p>- Run the project.</p> <p>As you probably expected, the program did resolve ICustomerService and injected a CustomerService instance into the InvoiceManager.CustomerService property.</p> <p><u>Dependency injection by method call</u></p> <p>You can do pretty much the same thing using a method call instead of a property.</p> <p>- Replace the CustomerService the property by a SetCustomerService() method:</p> <blockquote> <p><font face="Courier New">[InjectionMethod] </font></p> <p><font face="Courier New">public void SetCustomerService(ICustomerService service) </font></p> <p><font face="Courier New">{ </font></p> <p><font face="Courier New">    _customerService = service; </font></p> <p><font face="Courier New">}</font> </p> </blockquote> <p>In the case of a method, use the [InjectionMethod] attribute to indicate to UnityContainer that a dependency injection is required.</p> <p>- Run the project.</p> <p>And of course, the program did resolve ICustomerService and injected a CustomerService instance by calling the InvoiceManager.SetCustomerService method.</p> <p><u>Note on dependency injection by constructor</u></p> <p>We have already seen dependency injection through the constructor but there is one important note about this: If your class has multiple constructors, your must annotate the constructor you want UnityContainer to use by adding the [InjectionConstructor] attribute on it.</p> <p>Conclusion</p> <p>Hopefully this tutorial will you get started with the Unity Application Block. </p> Sylvain Hamelhttp://www.blogger.com/profile/02893038274559437241noreply@blogger.com20