Over the next couple of weeks I will be diving down into Nhibernate. It is only fitting that today I spend a little time showing you how to add the DLL files that you need to start your project and the basic configuration for it. At times throughout these articles I may pause to discuss some of the open source technologies surrounding NHibernate and how they may better your solution and development process. So, let’s dive in click “continue reading” below to start.Nov 30: Starting NHibernate | Adding DLLs
Over the next couple of weeks I will be diving down into Nhibernate. It is only fitting that today I spend a little time showing you how to add the DLL files that you need to start your project and the basic configuration for it. At times throughout these articles I may pause to discuss some of the open source technologies surrounding NHibernate and how they may better your solution and development process. So, let’s dive in click “continue reading” below to start.Nov 25: ASP.NET MVC Email Template Solution
If you are like me then you have probably ran into a wall with using ASP.NET MVC View Engine to render your awesome Dynamic HTML Email Templates. At least you put up a fight using a lot of fake data. It is actually possible to get around it!
var oldContext = HttpContext.Current;
HttpContext.Current = new HttpContext(HttpContext.Current.Request,
fakeResponse);
var html = new HtmlHelper(new ViewContext(fakeControllerContext,
new FakeView(), fakeViewDataDictionary, new TempDataDictionary()),
new ViewPage());
html.RenderPartial(viewName, viewData, viewDataDictionary);
HttpContext.Current = oldContext; //yay
Though, because you’re reading this you’re like me and you never give up! So how, how do you get around all of this? The answer is Spark. Eeek, another DLL? Yes, Spark is its own View Engine which is an entire different framework. Yes, you have to go to their website download the DLLS, put it in your Lib folder and reference it in your code. Let me tell you now, it is well worth it. Let’s dive in!
Let’s write the code to render our email using the Spark. We want our code to take in the template name, something like: “ForgotUsernameEmail.spark” and we also want it to reuse our current ViewData Object which is of type ViewDataDictionary and contains Person data, we will need to add this into our own implementation of AbstractSparkView. See samples bellow:
Render Email Method:
public string RenderEmail(string sparkViewName, ViewDataDictionary
viewData)
{
var email = new StringWriter();
var view = (EmailTemplateBase) _engine.CreateInstance(new
SparkViewDescriptor().AddTemplate(sparkViewName));
view.ViewData = viewData;
try
{
view.RenderView(email);
}
finally
{
_engine.ReleaseInstance(view);
}
return email.ToString();
}
Oops thanks Arnis, forgot to mention EmailTemplateBase is just an extended version of AbstractSparkView that includes the ASP.NET MVC ViewDataDictionary.
Custom Spark AbstractSparkView with ViewData implementation:
public abstract class EmailTemplateBase : AbstractSparkView
{
public ViewDataDictionary ViewData { get; set; }
public object Eval(string expression)
{
return ViewData.Eval(expression);
}
public string Eval(string expression, string format)
{
return ViewData.Eval(expression, format);
}
}
So that’s done, let’s make the template… In my MVC Web Project I am going to add into my Views folder or maybe even Views/Email
a file called “ForgotUsernameEmail.spark”.
Dear ${#name}:
<p>
Your username is ${#userName}.
</p>
Thank You.
<use file="~/Views/Email/Signature"/>
I also put in a use tag to pull down a Signature file, since this is the same in everyone of my emails. Now let’s actually write the code to call it:
string email = RenderEmail(“ForgotUsernameEmail.spark”,ViewData);
And that’s all you need to do, well besides read up on spark syntax: http://www.sparkviewengine.com/documentation/configuring
Nov 24: Jumpstart your ASP.NET MVC Project
I’m going to start by talking about the frameworks I found useful without boring you with what an MVC framework is composed of. So let us start:
ASP.NET MVC 2.0 – http://www.asp.net/mvc/download/
Of course, the first would be the actual base framework. Currently in Beta, it is expected to hit RC1 half way between its final release with Visual Studio 2010 in March 2010. I strongly encourage you to utilize the Beta version and upgrade to the RC1 when it is released.
Spark View Engine – http://sparkviewengine.com/
The spark view engine, is what most would call a “true” MVC view render engine. I personally like this engine because it has the ability to be a “general purpose template engine” as well as a view engine. The down side with the ASP.NET MVC view engine is that: outside of your HttpContext/ControllerContext it renders itself to be completely useless for Rendering Views.
With Spark, you can build up templates anywhere you reference your Spark.dll. What’s the point of this? Let’s say you want to build up an Email Template, which uses dynamic data. Spark is your best bet for that. I’ll go into this in a later tutorial.
AutoMapper – http://automapper.codeplex.com/
The AutoMapper framework is catching eyes in the MVC community and might someday have a great influence on the actual ASP.NET MVC Framework. To put it in the simplest terms: automapper takes your domain objects and translates them into your view model objects, with minimal coding from you. If you ever find yourself writing large amounts of redundant translation code for your data objects, chances are you need this framework.
Dot Less CSS – http://www.dotlesscss.com/
The Dot less framework is actually is a .NET implementation of the LESS framework for Ruby. The LESS framework is a wrapper for CSS that allows you to write clean CSS by using “variables, mixins, and nested rules”. It is very easy to setup, and can clean up your CSS files by a lot. You could think of it as a head start on CSS3 and avoid CSS HELL.
JQuery – http://jquery.com/
Is a JavaScript framework for those of us who hate writing JavaScript. This framework makes it easy to select dom objects, writing events, apply styles, run effects, and most importantly write AJAX calls to your ASP.NET MVC Application.
NHibernate – http://nhforge.org/
One beast to rule them all. NHibernate is an ORM framework that allows you to bind your domain layer objects to your relational database. If you hear people talking about a data access layer this is where this framework will exist. I recommend anyone to read as much as they can on this framework. It plays a big part in the MVC world and making sure that your data access is smooth and simple in the long run.
Linq to NHibernate – http://sourceforge.net/projects/nhibernate/files/
If you have not heard of Linq then you probably have a lot of catching up to do. Thanks to Oren Eini we now have full Linq support for Nhibernate, no need for that pesky Hibernate Query Language. As a note, it can usually be found in the NHibernate repository and will usually be one build behind in its own DLL File.
StructureMap – http://structuremap.sourceforge.net
Inversion of Control, Dependency Injection, yeah I had my head spinning if not still from all the ongoing conversations about all these fancy words
. Surprisingly enough, I realized when I was done reading about it; I had used something similar to this back in my Java/Spring days.
What is it, what does it do? It is a design pattern nothing more which through interfaces allows you to remove dependencies on concrete classes, and “inject” locate, put, setup (whatever) those interfaces based on a set of rules. This type of pattern will be very useful in developing your growing web application. Structure map is just a framework that I have come to like after exploring other IoC containers such as Windsor.
Moq – http://code.google.com/p/moq/
This is a mocking framework pronounced mock-you that allows you to mock up interfaces and classes in your testing framework, to avoid things such as connecting to your database or services. I have a few tutorials already posted up on the website on how to utilize this technology, feel free to explore them and utilize them.
Sharp Test Ex – http://sharptestex.codeplex.com/
This is a fun little framework that lets you write fluent assertions for your unit tests and at the same time really helps you write the tests you really should be writing. Check it out you will see what I mean.
WebAii – http://www.artoftest.com/products/webaii.aspx
I have been using this front end unit testing framework for quite a while now, and it hasn’t failed me yet. Though I can’t say I am a big fan of the other tool which “attempts” to generate the testing code for you. This little framework is awesome, and really easy to use if you are more a developer then a tester.
And that is for now. I look forward to starting off this series of tutorials with How to build an Email Template Manager with Spark.
Apr 21: Moq Testing Tutorial
In this tutorial I will take you through a mocking framework called Moq for (.NET 3.5) released under the New BSD License. Although, I will not be discussing what Mocking is for that is outside the scope of this tutorial. You can find out more on this by going to: What is mocking/mock object? This tutorial has in depth information how to peruse using this framework along with many sample code snippets.Apr 20: Going Social
Another update! Every post will now have the ability for you to share our links. We know at this point there isn’t much to share but we are working on it. Also a little more customization is coming soon to the website.Apr 18: Updates To CowFarm
I just wanted to let you know that I am currently pushing many updates to the website. So there are going to be a lot of problems here and there. Please, bare with me as I get the site functional. I have also been hit by a lot of bots recently so I decided that I will have to approve your comment whenever you post.
Also many links are not functional yet. I will hover be slowly rolling out a set of new features such as code dump which will contain lots of uncompleted/completed code projects released under the Creative Commons Licenses.
Mar 19: Internet Explorer 8, Not Really!
You might as well update to Internet Explorer 8 today, it’s not much of an improvement over any other IE browsers you have used. It still asks you to restart your machine, it still takes 40 minutes to install, and it still tries to update your computer at least four times during your install. We know that Microsoft is a large corporation with a lot of power to do good. What we don’t get is why the fail to utilize this power to “Start Over!” imagine if Microsoft released a whole new browser, different branding different technologies, that would surely spark our interest!
Mar 18: Blend 3, SuperPreview (Web 3), Silverlight 3
After the first day of Microsoft’s MIX 09 we are left to explore all of the new tools and updates that have been released. After running the released demo’s, I am left with some thoughts. Oh, of course I shall point you to the downloads so you can have the full experience too.There is nothing better then getting a good hands on. Although there aren’t many of these features available right this moment, what is out is worth jumping on top of while you have the chance. So go ahead and explore by clicking continue reading below.
Mar 13: IEmailTemplateService, Headers/Postback WorkAround
I spent the day with ASP.NET MVC EmailTemplates, and IEmailTemplateService recieving an error from IIS that HTTP Headers have already been sent (Response.Headers) or just a sent email without any call back to our browser. I dived down into the MvcContrib source code (IEmailTemplateService.RenderMessage), started seeing code dealing with Response.Filters and MemoryStreams, OutputStreams(TextWriter), and firing View.Render.




There is a lot of technical power within photoshop, we are here to exploit it.
Content relating to scripting languages such as javascript and their relating frameworks such as mootools and jquery.
Coding content relating to the core .NET framework for developing C# and C++.
Anything relating to web technologies and development.
Articles on sql and database relating articles such as hibernate and ejb.



