Archive for October 6th, 2009

AutoMapper Introduction and Samples from NETDUG

In September, Cory Isakson and I presented AutoMapper to the Boise .NET Developer User Group (NETDUG).  As promised, I have included the sample code here.  AutoMapper 1.0 RC1 is available on the CodePlex site.

At my company, we have embraced convention-over-configuration throughout our applications, from our data access framework (Fluent NHibernate) to our IoC container (StructureMap) to our build scripts to our…well, you get the picture.  However, we had been hitting a pain point in our application when trying to serialize our domain objects for transport across the WCF service layer.  We were also seeing some issues with using domain objects directly in our MVC views. The old way would have been to write that boring left-hand/right-hand code.  We all know that left-hand/right-hand code is ugly and pollutes the methods that should be doing real work with ceremonious busy work. 

Well, just as we were really getting stung by these pain points, Cory and I started talking about AutoMapper.  Now, for those who have no idea what AutoMapper is, check out the Getting Started page on CodePlex.  If you want to check out the source, go to the Google code site.  Jimmy Bogard, the AutoMapper author, describes the AutoMapper as a convention-based object-to-object mapper.

 

Different Means to an End

 

Here is the basic idea… In the past, I would write this classic chunk of code:

var meeting = _repository.GetMeetingById(meetingId);var dto = new MeetingDto();dto.Begins = meeting.Begins;dto.End = meeting.End;dto.Attendees = meeting.Attendees;dto.AttendeesCount = meeting.Attendees.Count;//do something meaningful

With AutoMapper, I can write this instead:

var meeting = _repository.GetMeetingById(meetingId);var dto = Mapper.Map<Meeting, MeetingDto>(meeting);//do something meaningful

 

Herein lies the beauty of AutoMapper.  When your classes align themselves conventionally, your mapping configuration can be as simple as:

CreateMap<Meeting,MeetingDto>();

This is a trivial example, but where AutoMapper shines is in the ability to map lists and nested properties by convention. Or constructing an object based on another object’s properties.  All without littering a method with ceremonial code.

Using an object-to-object mapper does have its drawbacks:

  1. The classic left-hand/right-hand code performs faster than mapped code, although Jimmy has made great strides in increasing performance.
  2. When defining unconventional mappings, you will still have left-hand/right-hand code
  3. There will be a learning curve for you (and/or your team) if you have not had experience with convention-based frameworks or some of the .NET 3.5 features.

However, we have found these drawbacks to be trivial when compared to the benefits.

 

    Mapping Toolset

    In addition to providing the convention mappings, Jimmy has provided a toolset for enhancing the mappings. Listed here are several tools we either use or find compelling.
    Custom Converters: Code to convert from source type to destination type. Defined once and implicitly used for all mappings. 
    Custom Resolvers: Code to convert from source value to destination value.  Defined once for use by any mapping, but must be explicitly used by a mapping.
    Custom Formatters: Code to reformat a type for presentation.  Like resolvers, formatters are defined once and explicitly used.
    Before/After Map Functions: Provides the ability to run custom code before or after the mappings are performed.

    Validation Assertion: Provides a method to short-circuit at runtime (or in tests) with an explanatory exception when a mapping may cause failures. 

    Mapping Profiles: Profile is a base class that helps you organize your code.  If you are familiar with StructureMap’s Registry class, you will feel right at home with the Profile class.

     

    Where We Use AutoMapper

     

    We use AutoMapper to transform our object model to our presentation model.  This happens in two places – in our MVC controllers and at our WCF service layer.

    In the controllers, we will map from a domain model or DTO into the view model.  We will also map from our view model into a message object for use by the service or domain.

    At the service layer, we flatten our domain model into a DTO or map a message object to run a command against the domain.

     

    Code Samples

     

    I am including the sample code used at the NETDUG meeting.  The first sample shows different ways to setup mappings (inline vs. profiles).  The second sample shows some usages of custom resolvers, formatters, and before-maps.

    Download the AutoMapper source.  Jimmy has provided many sample classes and unit tests showing off the usage of different conventions. 

    Matt Hinze also posted a sample solution using AutoMapper with NerdDinner (of which I borrowed some custom formatter code – Thanks Matt!).

    Download the CodeCampServer source.  It is full of examples and conventions, including using an IoC/DI implementation of the AutoMapper engine.


Themes and Plugins For Extreme WordPress Functionality

WordPress is one of the most popular blogging software with large community behind it. There are numerous themes and plugins which allow you to easily create and manage corporate, news paper, magazine type of websites with it. Due to its popularity and ease of use, developers are constantly looking for ways to extend WordPress even further.

Amazingly WordPress has proven to have a really robust architecture allowing developers to take WordPress beyond blogging. W3Avenue has compiled a list of themes and plugins which allow you extend functionality of your WordPress powered website beyond a blog with minimum effort.

Frankly speaking every plugin is suppose to extend functionality of your WordPress installation in some way. WordPress themes are meant to customize the look and feel, but there are many which also extend its functionality. Our list consist of themes and plugins which either change the overall function of your website from a blog to something else or add new function that will otherwise require a separate software.

Discussion Forum

  • OnePress Community
    The OnePress framework is an integrated website and forum solution. It is, simply, a WordPress theme to serve as the foundation and framework for your web site and online community. Leveraging the powerful WordPress and phpBB projects, OnePress provides a set of features focused on helping you build and maintain your site from the inside out. With this set of tools, you can easily run your community and do so with professional presentation.
  • Simple:Press Forum
    Simple:Press is a feature rich forum plugin for WordPress. It fully integrates into your WP based site utilizing the same user records and database and displaying on a single WP page. It is fully customizable and comes with a number of skins and sets of icons to get your started.

Membership Site

  • Members Only
    Members Only is a WordPress plugin that allows you to make your blog only viewable to visitors that are logged in. If a visitor is not logged in, they will be redirected either to the WordPress login page or a page of your choice. Once logged in they can be redirected back to the page that they originally requested. You can also protect your feeds whilst allowing registered user access to them by using Feed Keys.
  • WishList Member (Commercial Plugin: $97)
    WishList Member plugin is a membership script that can turn any WordPress blog into a full blown membership site. Popular features include Total Content Protection, Sequential Content Delivery, Easy Member Management and much more.
  • Suma (Commercial Plugin: $199)
    Suma is a Membership and Subscription Management plugin for the WordPress publishing system.  It provides functionality that transforms WordPress into a pay-to-view, membership-oriented, subscription-based content publishing platform.

News Aggregator

  • FeedWordPress
    An open-source Atom/RSS Aggregator plugin for the WordPress weblog software. It syndicates content from feeds that you choose into your WordPress weblog; if you syndicate several feeds you can use WordPress’s posts database and template engine as the back-end of an aggregator (”planet”) website.
  • OneNews (Commercial Theme: $49)
    Commercial WordPress Theme that allows you to create a single-page news aggregator like Popurls or multiple-pages news aggregator like Alltop. It allows you to add and arrange feed blocks for normal text feeds; Flickr feeds; Youtube, Metacafe and Dailymotion feeds; and any PHP or HTML code, including JavaScript.
  • WP-o-Matic
    WP-o-Matic plugin makes automatic blogging a snap by automatically creating posts from the RSS/Atom feeds you choose, which are organized into campaigns.

Email Newsletter / Notifications / Mailing List

  • MeeNews
    A WordPress plugin that lets you customize the layout of the template as you like, manage mailing lists, create newsletters, etc. Its configuration is very easy and simple and does not require much knowledge of programming; compatible with all major email clients: Outlook, Thunderbird, Gmail, Hotmail, etc.
  • MailPress
    MailPress is a WordPress plugin that will add Newsletter Mailing functionality to your blog. MailPress allows you to send text or HTML based emails from your WordPress.
  • Subscribe2
    Subscribe2 WordPress plugin provides a comprehensive subscription management and email notification system for WordPress blogs that sends email notifications to a list of subscribers when you publish new content to your blog.

e-Commerce Site

  • WP e-Commerce
    The WordPress e-Commerce plugin is a state-of-the-art e-Commerce platform with a focus on aesthetics, web standards and usability. It integrates with Google Checkout, Paypal, Authorize.net, Payment Express and many other trusted payment processors.
    Free Themes Using WP e-Commerce Plugin: SimpleCart(js), Crafty Cart, Vanilla Cart, wpStore
  • ShopperPress
    ShopperPress is a fully featured shopping cart plugin for WordPress, suitable for selling any types of products, services, and digital downloads online. It has built in support for multiple payment gateways allowing you to accept product payments online.
  • Market Theme (Commercial Theme: $55)
    The Market Theme is a fully featured WordPress theme that transforms a standard installation of WordPress into an e-commerce storefront. Utilizing custom fields all over the place, Market allows you to easily add products, set prices, and instantly create buy now buttons automatically.
  • Shop (Commercial Plugin: $55)
    Shopp is an e-commerce plugin that adds a feature-rich online store to your WordPress-powered website or blog.

Gallery Site

  • Snapshot
    Snapshot is a flexible WordPress theme from WooThemese that can be used for either a photo showcase, portfolio or design gallery. It provides two different theme layouts / capabilities to allow you to switch between a photoblog / portfolio showcasing your own work or using Snapshot as a design gallery.
  • CSS Gallery
    A CSS Gallery Wordpress theme for webmasters who want to build CSS showcase or web gallery. Packed with built in Tagging, Google ads and a sidebar block with 125 x 125 banner ads. Theme is valid XHTML 1.0 transitional and valid CSS.
  • More Themes: Gallery, CSS Gallery Theme 2.0

Micro Blog

  • P2
    A group blog theme for short update messages, inspired by Twitter. Featuring: inline comments on the homepage, a posting form right on the homepage, inline editing of posts and comments, real-time updates so new posts and comments come in without reloading, and much more.
  • TWEEM (Commercial Theme: $15)
    WordPress theme that let you create your own Twitter Microsite. Features include: ability to create up to 4 tabs of Twitter search stream; easy configuration using built-in theme options; powered by jQuery; built on BluePrintCSS for easy customization.

Job Board

  • JobPress (Commercial Theme: $79)
    JobPress is a WordPress theme that turns your website into a perfect working Job Board Software. It comes with all features a website of this kind needs; its easy-to-use, easy-to-customize, easy-to-read and a great way to monetize.

Review Site

  • GD Star Rating
    GD Star Rating plugin allows you to set up rating and review system for posts, pages and comments in your blog. You can set many options for displaying the rating stars, and also add widgets into the sidebars for displaying top ratings and other statistics generated by the plugin. Plugin includes advanced settings panels that will allow you to control many aspects of rating. Plugin also supports multi ratings along with thumbs based ratings. Plugin supports use of cache plugins and dynamic loading of data using AJAX.
  • WP Review Site (Commercial Plugin: $97)
    WP Review Site plugin turns WordPress into a powerful review site engine, allowing you to easily create user-powered review sites on virtually anything – review products, services, websites, restaurants, hotels, credit cards! Use it to run a complete affiliate review site, or add star ratings to your existing website or blog.

Event Management

  • Events Manager
    Events Manager plugin is a full-featured event management solution for Wordpress. Events Manager supports recurring events, venues data, RSVP and maps. With Events Manager you can plan and publish your tour, or let people reserve spaces for your weekly meetings. You can then add events list, calendars and description to your blog using a sidebar widget or shortcodes; if you’re web designer you can simply employ the template tags provided by Events Manager.

Directory

  • Business Directory
    The Business Directory plugin for WordPress is an easy way to host a free Directory page for your readers, affiliates, advertisers, community or club members. Invite them to submit a simple advertisement listing for themselves on your blog. Listings include company name, a short description, and contact information including a live URL. The plugin includes an admin tab that allows you to approve of listings before they appear live on the site. You can also edit and delete listings.

Contact Management

  • WP-CRM
    WP-CRM is a WordPress system for creating a basic Contact Manager / CRM.  The system requires a combination of plugins and a theme. Features: Add contacts from the front end of WordPress; Associate an image with each contact; Assign each contact to a company… or don’t; Create a note history for each contact; Clickable email and website links; Google map contacts address; Dial a phone number; Fully hcard / vcard compatible.

FAQ Management

  • iMasters WP FAQ
    You can use iMasters WP FAQ plugin to manage FAQ in your WordPress based site. Organize your FAQ’s in categories and put them in posts or pages.
  • FAQ-Tastic Lite
    FAQ-Tastic Lite is a multiple FAQ plugin for WordPress that makes it easy for you to answer questions from your site visitors. FAQ-Tastic can handle multiple categories of questions on your site.

Wiki

  • WordPress Wiki (Commercial Theme: $30)
    The “WordPress Wiki Theme” is created with idea that anyone can have a Knowledge Base or Wiki in a few easy to follow steps. The theme come with six color variations to choose from and is very easy to customize. Built with a custom Frequently Asked Questions plugin to help extend the functionality of your web site. The plugin acts as a custom write panel that displays in essence short FAQs below posts in their respective categories.

Classified / Auction Site

  • Another Wordpress Classifieds Plugin
    This plugin is designed to allow you to add a classifieds ad section to your blog. You can use it to add pretty much any type of classified ads service that can run under a simplified structure taking some basic information from the user.
  • Classified Ads Theme (Commercial Theme: $49)
    ClassifiedTheme is a Premium Wordpress theme that lets you transform your wordpress or blog website into a genuine classified website. Some of its features include: PayPal integration, autodelete old posts, set ad period and lots more. You can turn your blog into any classified ads type of site, like: auto/car ads, real estate ads, PC Ads, food ads, high-tech ads, etc.
  • WP Auctions (Commercial Plugin: $39.99)
    WP Auctions plugin enables you to host auctions on your blog.Features include: use any currency; place auctions in a post or page; auctions for registered users only; accept PayPal, wire transfers or checks; sell items on “Buy It Now” basis; upload multiple images for each auction.
  • Reverse Auction Theme (Commercial Theme: $54)
    This premium theme allows you to transform your WordPress based website into a genuine auction or reverse auction website.

Marketing / Sales

  • Affiliate Theme (Commercial Theme: $97)
    This theme allows you to build new affiliate websites using WordPress.
  • FlexSqueeze (Commercial Theme: $129.99)
    WirdPress theme that allows you to create niche blogs for affiliate or AdSense purposes.

Additional Resources

Please feel free to suggest any addition, correction or updates in your comments. You may also be interested in reading following posts published on W3Avenue:

Similar Posts:


Creating a Filtering User Interface With jQuery In a Web Forms Application: Part 1

jQuery is a lightweight, cross-browser JavaScript library designed to ease JavaScript's most common tasks, including inspecting and manipulating the Document Object Model (DOM) and making out of band HTTP requests to support AJAX functionality. In plain English, jQuery makes it easy to perform client-side tasks like adding or removing attributes or CSS classes to elements in the DOM, or showing or hiding elements on the page in response to a user action (such as clicking a button). jQuery is used by many popular Web 2.0 sites to help implement rich, interactive features. jQuery can certainly be used in an ASP.NET application, although integrating client-side script into a Web Forms application can sometimes be a bit trying. JavaScript development fits more naturally with ASP.NET MVC applications; in fact, the ASP.NET MVC framework includes the jQuery libraries. What's more, Microsoft has announced that jQuery will be included with Visual Studio 2010 and beyond.

I recently had the opportunity to use jQuery in a intranet-based line of business Web Forms application. This application has a number of reporting screens that use a GridView control to display the report results. Users often want to filter the results to get a more concise snapshop of the data they are interested in, and to that end many of these reports include a filtering user interface, which is a series of drop-downs, checkboxes, and textboxes, through which they can apply various filtering criteria.

Some of these filtering user interfaces have gotten so expansive that nearly an entire screen of real estate is chewed up by the filtering user interface alone! We needed a way to collapse this filtering interface and only expand it upon user request. Using jQuery, some CSS, and a few lines of JavaScript, I was able to implement an entirely client-side approach to expanding and collapsing the filtering interface. This article, Part 1, walks through the nuts and bolts of this functionality. The upcoming Part 2 looks at how to extend the collapsible filtering user interface functionality so that it remembers the collapsed/expanded state on a user-by-user basis. Read on to learn more!
Read More >


Preparing for Multi-touch in Flash – A Primer

WOW! Can you believe it?! Adobe MAX Day 1 is complete, and we have seen a ton of new and exciting announcements. It's hard to think we have more to go. Being a die-hard Flash developer, you can guess which...

Flash for iPhone, WebOS and Windows Mobile

Adobe MAX 2009 is underway and yesterday during the keynote Adobe announced Flash 10.1 for mobile phones. It's a new runtime with improved performances and memory usage with support for new mobile platforms such as the Palm Web OS and...

  • Sponsored Links

  •  

  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress