Notes from TekPub ASP.NET MVC3 series of tutorials.
- Startup – big idea.. charge people money for
- Good idea, well executed
- Get site out there and pay the bills!
Why MVC3 in this Fast Paced Startup?
- Good stable version of MVC
- I know C#
What are we doing (Elevator pitch) and when are we going to do it?
1 sentence!
Platform and Tools
MVC3
Unfuddle for project mgt

or agilezen (kanban)
Source is on http://github.com/tekpub/mvc3
Setup a new MVC3 solution called VidPub.Web

Lib is for external dlls. Docs are for docs. Everything is under git
git init in \dev\VidPub
git add .
git commit –am “Initial load”
DropBox
mkdir e:\dropbox\repositories\vpub

in e:\dropbox\repositories\vpub
git init –bare
from \dev folder git push origin master

So other people can then pull from that repository… it is the whole repo up there, not just source.
Test Project
Have just created a container.
Authentication
Don’t want concurrent authentcation.. ie users sharing accounts. Could use token based.
Now, 1 Year, 3 Years
ASP.NET Membership – complicated..
Consistency of FileNames
Public\javscripts
Public\stylesheets
no more content directory
Model\AccountModels.cs to AccountModel
change CSS path in _Layout.cshtml
CDN
http://code.google.com/apis/libraries/devguide.html#jquery

make faster for user as they may have this cached in their browser. Also save us a bit of bandwidth. Cache up to a year.
If using Azure to host http://www.microsoft.com/windowsazure/msdn-benefits/ MSDN have got some benefits.
Logging
NLog using NuGet
Code Snippet
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<targets>
<!--Useful for debugging-->
<target name="console" xsi:type="ColoredConsole"
layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
<target name="file" xsi:type="File" fileName="${basedir}/App_Data//logs/site.log"
layout="${date}: ${message}" />
<target name="eventlog" xsi:type="EventLog" source="My App" log="Application"
layout="${date}: ${message} ${stacktrace}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
<logger name="*" minlevel="Fatal" writeTo="eventlog" />
</rules>
</nlog>
in dev we’re going to log everything to a file in App_Data/logs
In \Infrastructure we’ve got some code to help us log with an interface extracted.
Code Snippet
public class NLogger : VidPub.Web.Infrastructure.Logging.ILogger {
Logger _logger;
public NLogger() {
_logger = LogManager.GetCurrentClassLogger();
}
public void LogInfo(string message) {
_logger.Info(message);
}
public void LogWarning(string message) {
_logger.Warn(message);
}
public void LogDebug(string message) {
_logger.Debug(message);
}
public void LogError(string message) {
_logger.Error(message);
}
public void LogError(Exception x) {
LogError(BuildExceptionMessage(x));
}
public void LogFatal(string message) {
_logger.Fatal(message);
}
public void LogFatal(Exception x) {
LogFatal(BuildExceptionMessage(x));
}
string BuildExceptionMessage(Exception x) {
Exception logException = x;
if (x.InnerException != null)
logException = x.InnerException;
string strErrorMsg = Environment.NewLine + "Error in Path :" + System.Web.HttpContext.Current.Request.Path;
// Get the QueryString along with the Virtual Path
strErrorMsg += Environment.NewLine + "Raw Url :" + System.Web.HttpContext.Current.Request.RawUrl;
// Get the error message
strErrorMsg += Environment.NewLine + "Message :" + logException.Message;
// Source of the message
strErrorMsg += Environment.NewLine + "Source :" + logException.Source;
// Stack Trace of the error
strErrorMsg += Environment.NewLine + "Stack Trace :" + logException.StackTrace;
// Method where the error occurred
strErrorMsg += Environment.NewLine + "TargetSite :" + logException.TargetSite;
return strErrorMsg;
}
}
IoC
So we don’t have anything coupled tightly right from the start (eg logging which we’re doing next).. lets use IoC
Ninject.MVC3
Wire up in global.asax
public class MvcApplication : NinjectHttpApplication {
**NO this is not correct as in MVC3 it is bootstrapped, so just leave as:
public class MvcApplication : System.Web.HttpApplication {
Setting up logging in App_Start bootstrapper file.
“Every time you see a request for ILogger interface in a controller, return a new NLogger class”
kernel.Bind<ILogger>().To<NLogger>();
added in Logs/Site.log into our project.
Glimpse
Added in bookmarks into bar to turn on and off.

git add .
git commit –am “Added logging, IoC and rearranged stuff”
git push origin master (to save to dropbox)
current state of play of our filesystem.
