Contents tagged with mvc

  • DogFoodCon Session on DDD with ASP.NET MVC

    Yesterday I presented at DogFoodCon, giving a slightly modified version of a talk I gave a week earlier at FalafelCON in San Francisco.  The session provides those with little knowledge of Domain-Driven Design with a rapid overview of some key concepts and patterns used in DDD, and wraps up with a brief demo of a simple Guestbook application that begins as a monolithic everything-in-the-controller MVC application but is improved using some DDD-based techniques.  The slides are available on Slideshare and embedded here: Add Some DDD to Your ASP.NET MVC, OK? from Steven Smith Both times I gave the talk, I ran out of time to show everything I wanted in the demo (sorry, it’s a big … more

  • Resolving Dependencies in ASP.NET MVC 5 with StructureMap

    In a previous post I showed how to use StructureMap with ASP.NET MVC 3.  It’s been a couple of years, so I figured it was time to update that article with the steps for getting StructureMap working in ASP.NET MVC 5.  If you’re interested in learning more about how to develop applications in a loosely coupled fashion, I highly recommend my course on SOLID Principles of Object Oriented Design to learn more (in particular, the Dependency Inversion Principle). StructureMap is my preferred IOC container / dependency injection tool for .NET applications.  It’s free, performs very well, and has a number of very useful features that make it very productive to work with.  One … more

  • Wiring Up TimeAgo and ASPNET MVC

    Imagine you want to display something on a page so that instead of raw dates, the user is shown something more relative to the current time.  You’ve probably seen this in some of the applications you use.  “Last Updated: A moment ago” or “about an hour ago”.  There are a variety of ways you can implement this, and it’s been done in many different languages.  In my case, which is an ASP.NET MVC C# application, I considered doing it on the server and simply passing the result as a string to the view for display.  However, in searching for the best way to do this, I stumbled upon the Timeago plugin for jQuery. One of the key benefits of this plugin is that, unlike … more

  • Getting StructureMap to Work with MVC4 RC and Web API

    At the moment (18 July 2012) if you install the NuGet package structuremap.MVC4, it will not compile due to breaking changes in the ASP.NET MVC4 RC distribution.  You have to jump through some extra hoops to get this working.  Here are two posts that help: Configuring MVC4 with StructureMap Using the Web API Dependency Resolver However, even with both of these getting things working wasn’t quite as easy as I would have liked.  Here are two full files with namespaces showing what I used to get things working (Gist 3135943).  I assume the NuGet package will be updated to be correct once MVC4 ships. more

  • Beyond Role Based Authorization in ASPNET MVC

    A fairly frequent requirement in applications is to check for authorization to perform an action.  At the most basic level, this might just involve seeing if the user is authenticated (at all) or checking a flag to see if they are an Admin.  However, more complex requirements frequently include a variety of roles, and it’s quite common for the notion of ownership to be involved as well, with some actions being allowed if you own the item being worked on, and otherwise not.  I’ve written about using the notion of Privileges over Role Checks for this exact purpose in the past, as a way to ensure the logic of such decisions is properly encapsulated so that you can follow the … more

  • Getting Started with Single Page Applications in ASP.NET

    One of the new features in ASP.NET MVC 4 (Beta) is a new project template for Single Page Applications (SPA).  You can download the latest version of MVC4 from  Once you have that installed, get started by creating a new ASP.NET MVC 4 project: You’ll immediately be asked another question about exactly what kind of project you’re looking to create.  This is only asked on project creation, but it’s possible in the future you’ll be able to mix and match these kinds of templates and the resources they provide in a more ad hoc manner, after projects are created, in the future.  For now, though, to check out Single Page Applications, choose that … more

  • How Do I Use StructureMap with ASP.NET MVC 3

    Update: If you want to use StructureMap with ASP.NET MVC 5, I have a walkthrough on this now as well.

    As I write this, the best resource for official documentation on ASP.NET MVC 3 is of course MSDN.  You can also learn more about ASP.NET MVC 3 here.  However, neither of those mention how to properly set up an IOC Container (like StructureMap) with ASP.NET MVC 3.  After some searching, I was able to get things working using the RTM version of ASP.NET MVC 3.  Here’s what I had to do.

    Step One – Global.asax – Application_Start()

    First, you need to wire things up when your application starts.  You can put all of your container registration stuff … more

  • Software Design Best Practices Debate

    I've been following the discussion on Phil Haack's blog surrounding how best to introduce polymorphic objects into the MVC framework as part of the framework's interface for developers to work with.  In .NET, there are basically two ways one can build in this polymorphism: interfaces and abstract base classes.  There is a very vocal set of developers who seem to think that the answer must always be interfaces, and while I think interfaces are great and have their place, I think Phil makes some excellent points about their limitations when it comes to versioning.  In particular, his post on The Cost of Breaking Changes describes the scenario wherein a breaking change in the … more

  • MVC Getting Started

    Scott Hanselman has posted a very well done screencast on getting started with Model View Controller for ASP.NET, which I watched and did all the code for last night.  There was only one hangup in the code portion, which has to do with changes that were made post-production to the MvcToolkit.  The code given in the screencast doesn't work, but this simple fix does:<% using (Html.Form<ProjectName.Controllers.HomeController>(x=>x.Update(ViewData.ProductID))) { %> Anyway, Scott really went above and beyond on the production of this video, enough so that I wanted to call special attention to it.  I told him he should do a blog post and/or screencast on … more