Some times you need to cast from one object to the other, and then back again, the easiest way of doing this is using Interface casting, I’ve generated this simple project which show how it works.
If you are like me, I like to keep my Visual Studio environment as clean as possible, so if I can get away from adding any addins in to Visual Studio I will always go for that option.
So when it comes to testing I prefer to run with NUnit and run it as n external program.
To do this just right click on the unit test project -> choosing the properties option -> setecting the Debug tab -> choose “start external program” and enter the NUnit assembly path, in my case this is “C:\Program Files\NUnit 2.5\bin\net-2.0\nunit.exe”, next is to select the command line arguments and point this to your unit test dll,
e.g. “C:\Program Files\NUnit 2.5\samples\csharp\money\bin\Debug\cs-money.dll” /run
The “run” parameter will automatically run the loaded project
Alternatively you can use a Visual Studio add-in such as TestDriven.Net, this also provides NCoverExplorer to provide you with code coverage.
When you open up MVC out of the box, you get the basic configuration, after a little playing around you soon see areas that require enhancing to, not only make your application more flexable, but also easier to maintain.
Here are a number of additional tasks you can perform that will help with your application.
Which IoC to use?
Don’t worry, if you use the Common Service Locator it provides an adstraction over the IoC
How to validate?
I have already covered this one in a previous post, but I’d still go with xVal
Need to generate Themes?
I think it is so important to start correctly and generating the User Interface should be configurable, the easiest way of doing this is to implement a Theme, and Chris Pietschmann has do this for us, Implement Theme Folders using a Custom ViewEngine
Here is a copy of the source for safe keeping.
Need Ajax to work in MVC
Extend the UrlHelper
Placing all your assets in one place is not only a good idea, but it also means you can be more flexable if you want to programmically change the theme of your user interface.
Which can be used like this:
Using Strongtypes and keep away from Strings
It appears so easy with MVC to use String everywhere, just DON’T, generate an extension for the UrlHelper
Now in your view it will look like this
I’ve been hit before by Microsofts in build Testing within Visual Studio 2008, great to have this feature built in, BUT, and a big but in order to run the tests you need to have Visual Studio install, so if you try and setup a Continuous Integration server you will also be required to install Visual Studio.
So best to go with what works well and that is nUnit, simple and easy, and more importantly loosely coupled
With testing comes Mocking, and which framework do you use? I also always say keep it simple and easy, so I’m going with Moq, short for “Mock-You”, as this is the only Mock Framework that is built around .Net 3.5 and LINQ.
There are many ways of managing a Scrum Sprint, but I always look for the easy ways, I came across Deborah Hartmann, spreadsheet which I have found very useful and easy to get along with. Once you understand the processes of Scrum and what is required the spreadsheet speak a thousand words.
In object-oriented programming, mock objectsare simulated objects that mimic the behavior of real objects in controlled ways. A computer programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.
It is possible to perform integration testing on the Membership Provider, take a look at this blog entry to find out more Integration testing the MembershipProvider
Within the Project we are using Rhino Mocks, Oren Eini is doing a great job with this framework, and I think it’s the only one that seems to be keeping up with the latest features in .NET, other than TypeMock. Plus, it’s totally free to use. It’s also the only one other than TypeMock which does not require you to input strings for method names you’d like to mock, which is cool. It’s compelling to use it but the project is currently maintained by just one person. If Oren decides to drop it, or for any reason stop working on it, the book might turn out outdated quite quickly. Plus, it’s not very widely used, though it seems to be gaining in popularity.
When I am writing an application it is so important to make sure you record and log information correctly, there are a number of free loggers you can use
I have come to use NLog, by Jaroslaw Kowalski, it’s so easy to use and get up and running, which is what you really need if you are using a logger of any type.
But what is the best practice when using a log in a live environment?
Or more importantly what and how do you configure you configuration file to make sure you are logging all your information?
The way I see it is, capture your logging to the Event Log and a Database for information and tracing.
When it comes to Errors and Fatal logging then, write it to as many places as you can, an Error file, the Event Log, a Database Log, and perhaps a special Exception Database Log, because if something has failed, you’ll want to shout about it, and you want to record it in as many places as possible.
Here is an example of an NLog configuration
To setup the database use the following creation creation script
Make sure within the SQL Database you have a user “nloguser”, with a password of “nlogpassword”, these are both defined in the NLog configuration file, and can be changed if need be.
That is it, all you have to do now is wait for your live application to log some information.
I am sure there are a few other configuration options available and I welcome anyones comments on how to improve this configuration file.
Arrive on Friday night, preferably at city airport and head east to Brick lane for a curry. After dinner have drinks at the Vibe bar or 93 feet east. If you are feeling super energetic see what is going on at Sosho, Cargo or Electricity showrooms before getting a good night of sleep.
Saturday morning, get up early and have breakfast at Patisserie Valerie in Knightsbridge. Have a wander around Harrods for an hour or two making sure that you check out the food hall. Jump on the tube and head over to Camden. You may enjoy the market – I don’t – but if the chaos isn’t for you get off at Chalk Farm station rather than Camden to avoid it all. Grab lunch at Thanh Binh one of the best cheap Vietnamese restaurants in London, I recommend the Pho.
You are on your own for the evening. I don’t really do clubbing any more, but the one piece of advice I give is don’t just wander to Leicester square and choose a venue, there are some absolute hovels. If you are just after a few more drinks after dinner I like the bar at the Charlotte street hotel.
Sunday morning, make sure you enjoy a full English breakfast to start your day. Your hotel probably serves one and to be honest there isn’t any particular culinary skill involved in making one so it is hardly worth hunting down an ‘authentic greasy spoon’ cafe.
Get a tube to Westminster and walk over the bridge enjoying the uber tourist views of Big ben and the houses of parliament. Get a boat from Waterloo pier next to the London eye to Bankside pier, browse Tate modern for a while then cross the river using the millennium foot bridge, head up to St. Pauls Cathedral and check out thewhispering gallery.
Make sure you use the Thames Clippers commuter boats. The tourist boats are over priced and very slow.
Back on the boat to Greenwich, from Blackfriars pier. Walk through the grounds of the naval college and into the park, up to the observatory for another view over London. If you have time check out the three markets in Greenwich.
That is just one of many ways of spending a weekend in London. I missed out Fish and Chips, some great markets and many of my favourite pubs simply because of time constraints. I also tried to leave plenty of spare time between my recommendations so you can wander off the beaten track and discover your own London – in my experience, just wandering is one of the true joys of travel.
My final tip, here is what to avoid. Leicester Square, Theatre Land, The London eye, Buckingham palace. Some Londoners may passionately disagree, but I think you’d be wasting valuable time.
So, if you are reading this and thinking of visiting, enjoy my city. Arguably the greatest on earth.
I need to generate a Windows Service application, I’ve done this before, but could I remember how to do it. In my searching I found this code sample very useful Creating a Basic Windows Service in C# on The Code Project
Another useful article I found was from Microsoft Windows Services: New Base Classes in .NET Make Writing a Windows Service Easy
Okay you are developing a WinForm application and you are looking at performance, one area is Caching of information, but wait a minute I’ve been using caching in my web applications for sometime, but how do you do it from a WinForm application as you don’t have a host to store your cache.
Would you know it you can use the web cache too, just you have to take a few extra steps to retain your cache, either in memory or in temporary files.
You can use the HttpRequest to store the System.Web.Cache objects in your application, and this works well.
I also came across any Blog, providing another method to Caching, however I have a little concern over this method of caching in files as you are likely to get file locking.
I’ve written my own simple VB.NET application to show it working and just holding the Cache in memory for the life of the application.
Of course you could run a Windows Service which holds all the Cache information, this way it will be available to all your WinForm applications should you require it.
After using StructureMap for a while I thought it would be nice to generate a simple example of how it all works, so I’ve built in Visual Studio 2008, both C# and a VB.NET version.
For more information on StructureMap please go to their main website
If you need to know more about IoC’s then it’s worth making a look at the following links: