Tag Archive for azure

Pallet Town: Intro to the Repository Pattern MVC4

Pallet TownWelcome to Pallet Town! Pallet town is going to be an ongoing bi-weekly look at various development technologies and techniques from the perspective of someone new to that technology. For those who might know or (God forbid) are too young to get the reference, Pallet Town is the first town in the original Pokemon games for the Nintendo Gameboy.

I’ve been having a great time with Windows Azure  or more specifically ASP.Net MVC4. .Net developers will be familiar with the repository pattern, since it is a common pattern used in that community. Let’s take a look at a simple repository example using everyone’s favorite objects: Pokemon. To start we need a simple Pokemon class.

namespace PokeSample.Models
{
  public class Pokemon
  {
     public int Id { get; set; }
     public String Name { get; set; }
  }
}

We now need to create an interface:

namespace PokeSample.Models
{
  interface IPokeRepository
  {
    Pokemon Add(Pokemon pokemon);
    Pokemon Get(int id);
  }
}

And now it’s time for the repository itself:

namespace PokeSample.Models
{
  public class PokeRepository : IPokeRepository
  {
    private List pokemon = new List();
    private int nextId = 0;

    public PokeRepository()
    {
       // adding some test data
       Add(new Pokemon { Name = "Charmander"});
    }

    public Pokemon Add(Pokemon somePokemon)
    {
        if (somePokemon == null)
        {
           throw new ArgumentNullException("somePokemon is null");
        }

        somePokemon.Id = nextId++;
        pokemon.Add(somePokemon);

        return somePokemon;
    }

    public Pokemon Get(int id)
    {
       return pokemon.Find(p => p.Id == id);
    } 
  }
}

You’ll notice that we are seeding the ‘pokemon’ List and have creates some simple CRUD methods. The idea here is that you could call these methods in response to HTTP requests from the PokemonController. Assuming you’ve setup your dev environment correctly this should all work just fine on localhost.

However, there is one pretty obvious glaring issue with this implementation — the data is not persisted. Stay tuned for the part 2 of this series that will show how you can use the common DBContext (ok that’s my term but it’s catchy) pattern to persist your data using MSSQL or some other datastore.

Hope you enjoyed this first entry in Pallet Town and I would appreciate any feedback you might have to offer. Please feel free to contact me on Twitter or Google+.

ASP.Net — Good, Just Not for Me

If you’ve been listening to recent Coder Radio episodes or following this blog, then you probably know that I have been working on a side project (that I am no longer pursuing due to intense competition in the space and a general lack of interest on my part) in Microsoft’s ASP.NET MVC 4 and Windows Azure.  Overall, I really liked the developement experience of the stack and Visual Studio is still the best IDE (if you like that sort of thing) on the market today and of course C# was a delight to work in. Unfortunately, the downsides are just not acceptable for the type of projects I work on or first party products I plan to develop; those downsides being the cost of Azure, the cost of SQL Server, and Windows Server.

Azure is awesome. In a lot of ways it is very similar to Heroku: it has easy to configure Git deployment and is easy to configure and deploy. Unfortunately, it also shares Heroku’s penchant for premium pricing. To be clear, both services are great for prototyping or event the 1.0 versions of a project, but  if your project hits any sort of scale, you are going to be looking at some pretty hefty hosting costs.

SQL Server is interesting. I don’t know too much about it as it compares to databases I use on a regular basis (ie PostgreSQL). When I started looking into it, I was quickly derailed by cost. That’s right SQL server is one of those things that if you have to ask how much it cost you can’t afford it and that certainly turned out to be true for me. Though Azure does support MySQL, the default (and presumably prefered) implementation of MVC 4 is best used with SQL Server. Due to the aforementioned Azure hosting costs, I would likely want to migrate any successful projects onto dedicated servers or VPSs and that would mean having to pay for SQL Server licensing fees.

Speaking of licensing fees, let’s not forget Windows Server. To be fair, the cost of Windows Server is a lot less than SQL Server and seems to rolled into a lot of monthly VPS plans. Still, I really don’t like a lot of the decisions Windows Server makes, though Microsoft has made some effort to address this issues in Windows Server 2012. In a lot of ways I just prefer working with a Linux (Ubuntu if at all possible)  server over Windows.

The natural question you may have is: “since you are scrubbing the project and don’t plan to use anything you may have learned about the stack, didn’t you just waste a lot of time?” I don’t think so. For one, I always feel that it is a good idea to broaden your horizons technically. More importantly, it was good to see how things are done in the more Windows centric world and it was a joy to interact with the .Net community. Comments? Questions? Share them with me on Google+ or Twitter. This post was made possible by Code Journal and Fingertip Tech, INC. If you are Github user please check out Code Journal and if you are interested in having an Android, iOS, or web app developed please contact me.

A Look at Azure and MVC 4

ASP.Net MVC 4 is amazing. There I said it! I know I’m supposed to be the ‘Mac guy’ or ‘Linux guy’ or possibly even the ‘Ruby / Rails guy’ depending on where you know me from but the truth is that I love all technology and often find myself trying out new platforms or playing with some shiny tech toy. For the last month or so ASP.Net MVC 4 has been that new toy along with Windows Azure.

The Good

Azure provides easy to use web-based GUI’s for basically everything you’d want to do to configure, administer, and monitor your app. If you’re not a fan of GUI’s, there are also commandline tools for Windows and Mac.

For you Heroku lovers out there, the MVC / Azure development and deployment experience is very similar to the Rails / Heroku experience. In fact, Microsoft has gone so far as to build in Git deployment to Azure and has even provided an easy to use web-based GUI tool for setting it up. Overall, I was really impressed with what I saw.

Visual Studio still rocks. I’ve been working with Visual Studio 2012 and have been loving the code generation and debugging tools it includes. It simply is one of the most advanced IDE’s on the market today.

Microsoft has come along way since the days of IE 6. .Net’s Razor View Engine provides full support for HTML5. Not only was I happy to see this, but I was also a little surprised to see how far they’ve come in the area of web standards.

The Bad

MVC 4 has one achilles heel: price. Azure itself, like Heroku is expensive, but with Heroku you can, though with a bit of effort, migrate to a generic Linux server. The issue with Azure is that you’d have to pay for a Windows server license and other licensing fees if and when you want to migrate off of Azure. However, the costs can really start to pile on when you factor in Microsoft SQL Server.

The Ugly

There’s not much ugly in the Microsoft web development stack these days.

The Bottom Line

Overall I am very impressed with what I saw and will be keeping a close eye on ASP.Net and Azure. If you’ve been a Rails or Django developer and have never taken a look at the Microsoft stack, Azure and MVC 4 are definitely the place to start.