Showing posts with label microsoft. Show all posts
Showing posts with label microsoft. Show all posts

Thursday, February 7, 2013

Building E-commerce Sites with MVC

For those of us who have spent most of our careers building business applications, the prospect of creating an e-commerce storefront can be quite daunting. Not only do you have to deal with calculating tax, estimating shipping and accepting payments, but employees need a way to manage products, discounts and marketing content. Thankfully, there's an open source e-commerce solution written in Microsoft ASP.NET MVC named nopCommerce that provides all this functionality and much more.

I was so impressed by both the functionality and the underlying architecture that I've created a presentation which I believe will serve as a great introduction to MVC as well as a tutorial on developing custom storefronts using nopCommerce.

We start off with a brief overview of basic MVC concepts accompanied by examples within the nopCommerce code. This includes strongly typed Razor views, HTML helpers, jQuery ajax calls, and fluent validation.

Once everyone understands how the website works, we dive into the infrastructure by introducing WCF services, using a generic repository with Entity Framework (EF4) and LINQ, as well as Dependency Injection (DI) with Automapper.

If you'd like to schedule this talk for your local user group, either request me through INETA or contact me directly.

UPDATE 7/13/2013
Thanks to the CodeStock crew and everyone who packed the room for my talk. Y'all had some excellent questions and I invite anyone with additional questions to comment below or contact me directly. Also, don't forget to provide feedback so I can improve the talk for next time.

Click here to view the presentation slides.

Thursday, November 22, 2012

Microsoft Fakes Bait and Switch?

Is it possible Microsoft tricked developers into adopting their code isolation framework in an attempt to force upgrades to the Ultimate version of Visual Studio 2012?

When I first learned about the Moles framework from Microsoft Research, I was excited at the possibilities for unit testing and began presenting it at user groups and conferences. I was even more excited after Microsoft announced that a new version of this framework, named Fakes, would be included with Visual Studio 11 (now 2012).

Microsoft's documentation originally indicated that Fakes would be included with both Premium and Ultimate, but early adopters noticed the VS2012 Premium release candidate did not include Fakes and the documentation was later updated to indicate it would only ship with Ultimate.

Meanwhile, Moles is no longer supported in VS2012. So where does this leave those who adopted Moles and use the Premium version of Visual Studio? It appears they will be forced to upgrade to Ultimate or abandon the use of Microsoft's code isolation framework.

I choose to give Microsoft the benefit of the doubt. I'm sure the original intention was to ship Fakes with the same versions as were previously compatible with Moles. Discontinuing Moles made sense when a new-and-improved framework was slated to take it's place. The decision to restrict the use of Fakes to Ultimate was surely made without considering the ramifications to their existing customers.

The question remains of what, if anything, Microsoft will do to address the needs of those customers that have been left out in the cold.

Monday, September 24, 2012

Memphis .NET User Group (MNUG)

Last week I mentioned that I'll be speaking at the NE Arkansas .NET User Group on the 27th. Since then, we've arranged for that presentation to be broadcast via Live Meeting and the Memphis .NET User Group will be joining us live. Someone local will monitor the meeting chat room and relay any questions or comments from the online participants.

UPDATE:
If you attended this talk and would like to provide feedback, you can do so at SpeakerRate.com.

Monday, September 17, 2012

NE Arkansas .NET User Group

I'm scheduled to speak at the Northeast Arkansas .NET User Group on September 27, 2012. The topic of this talk will be Testing the Untestable with Microsoft Visual Studio 2012 Fakes. I've given this same talk several times at regional conferences and user groups and an overview can be found on my blog, however one great thing about speaking at local groups like this is that the audience helps direct the session and we often end up focusing on areas that are most useful to that particular group.

While anyone is welcome to show up, the group leader has requested that attendees RSVP so they have an idea of how many to expect. See you there!

UPDATE:
If you attended this talk and would like to provide feedback, you can do so at SpeakerRate.com.

Tuesday, September 11, 2012

Great MVVM, WPF, SOA and EF4 Articles

I was asked to put together some links to articles that would help our IT department ramp up on some of the patterns and technologies we're using. By the time I was done with the email, I realized it might be of use to others outside our organization so part three of my MVVM with WPF series was born. There are many approaches and I highly recommend researching beyond this handful of articles, but for anyone not yet familiar with these concepts I hope they help.



The Model-View-ViewModel (MVVM) pattern helps to cleanly separate the business and presentation logic of an application from its user interface (UI). This separation is key for testability, maintenance and scalability.

Here’s an introduction to MVVM which illustrates how it leverages WPF data binding and commands.

The main difference between what we’re proposing and how they define MVVM in the previous articles is, by using a convention-based framework such as Caliburn.Micro and events/commands to wire up the View and ViewModel, they are completely decoupled allowing for better testability and future scalability. The Caliburn.Micro wiki has a good introduction to the functionality it provides.

This article gives a good introduction to Attribute Based Validation which allows us to keep validation logic down in the business layer and entities where it can then bubble up and be reflected in the UI.

If there’s interest in going deeper, here’s an article on using a Service Oriented Architecture (SOA) to decouple service providers from consumers allowing for greater reuse and insulating the application from core business logic.

Finally, a  series of articles outlining the use of a Generic Repository with Entity Framework 4 (EF4) to reduce the amount of plumbing that must be written and maintained for data access.



See also:
MVVM with WPF Series Part 1. Disconnected WPF Applications
MVVM with WPF Series Part 2. WPF MVVM with WinForms Controls

Thursday, August 9, 2012

WPF MVVM with WinForms Controls

This is the second part of my series on using MVVM with WPF. In the first article I discussed architecting disconnected applications and how MVVM was a great fit for WPF smart clients as well as Silverlight web clients. Now we move on to the process of refactoring an old Windows Forms application to use this new architecture.

The main concern with changing an underlying technology is the initial investment in rewriting code. To help mitigate this issue, WPF has provided a WindowsFormsHost element that allows us to host WinForms controls inside of a WPF Page. Obviously this limits how effectively we can leverage other features provided by WPF, however with a few workarounds it's a viable solution to avoid having to completely rewrite those old WinForms controls.

How easy is it to implement the WindowsFormsHost?
<WindowsFormsHost><wfh:WinFormsUserControl x:Name="LegacyUserControl" /></WindowsFormsHost>

Okay, it's only slightly more complicated than that. You will need to add add a reference to WindowsFormIntegration and possibly System.Windows.Forms (if it is not already referenced).

Now the question comes to how we interact with this control from our ViewModel since we can't use WPF bindings in our WinForms control. We can bridge this gap by adding events to our WinForms user control.


Then we wire up the events to our DataContext in our WPF Page code-behind.


While I generally prefer to avoid using the code-behind, we also don't want our ViewModel to be aware of the internal workings of our View.

The end result is our Windows Forms control interacts with elements in our WPF Page.

demonstration

Download Demo Source Code

Tuesday, July 24, 2012

Disconnected WPF Applications

I was recently tasked with presenting a plan to turn an existing WinForms program into an enterprise level application. They wanted to stick with a Windows client, but since each form would already need significant rework to extract the business logic, I suggested moving to WPF using the Model-View-ViewModel (MVVM) presentation pattern.

MVVM is basically a type of Model-View-Presenter (MVP) pattern that makes use of declarative bindings. State and logic are stored in the Presenter (ViewModel) which presents an abstract view of the UI with no knowledge of what View will implement it.

With the Presentation Layer taken care of, it was time to address the heart of the Application. The immediate need was for a smart client, however the solution was still very young and continually changing so it seemed a Service Oriented Architecture (SOA) would provide the most flexability and reuse. The question was how a disconnected client would use services.

Microsoft used to offer an application block for this specific purpose. The Disconnected Service Agent Application Block helped maintain a queue of web service requests while working disconnected (offline), then submit them to the server when it became available. Unfortunately, it is no longer being maintained and I have not found a suggested replacement. My guess is that they would encourage use of Sync Framework, which is designed to synchronize databases and files, but can use custom providers as well.

We're using Sync Framework to replicate data down to the client for offline use, but to utilize SOA and keep business logic/validation on the server we need a way of queuing web service calls and resolving any conflicts that occur. I'm currently in the process of researching whether a Sync Framework custom provider would be a good fit or if the old disconnected service agent application block would be a good starting point.

The existing relies very heavily on SQL stored procedures. Fortunately, Entity Framework (EF4) supports calling the existing stored procedures so they wont all have to be rewritten immediately. The plan is to gradually move business logic up into the application layer and use entity model. I've also added a generic repository to allow mocking.

I welcome feedback and suggestions. If you've tinkered with custom providers for Sync Framework or have suggestions for how to best queue and resolve service calls I'd love to hear from you, either by leaving a comment below or on twitter (@gainesk).

Tuesday, May 8, 2012

Testing the Untestable with VS2012 Fakes

One of the new features included with Visual Studio 2012 is the Fakes Framework which offers the ability to detour code at runtime and isolate functionality for true unit testing, regardless of whether the code was written with testing in mind.

I began speaking on Fakes back when it was a beta product from Microsoft Research called Moles. While the core functionality remains the same, Microsoft has streamlined the implementation and now calls the detour mechanism a shim rather than a mole.

If you have attended this or another of my talks at a user group or conference, please take a moment to share your feedback on SpeakerRate.

The PowerPoint is available on SlideShare and below are links to the code demonstrated in the presentation.

Demos
Y2K Checker (simple introduction)
DateTime Audit (avoiding non-deterministic tests)
File Reader (shimming file system access)
Repository (stubbing interfaces)

Resources
Visual Studio 2011
Fakes MSDN Documentation

Thursday, February 9, 2012

Microsoft PEX and Moles

Microsoft Research is currently beta testing a couple new frameworks that can make unit testing your code a breeze. Pex is a testing tool that analyzes code and generates unit tests. Moles is a framework that isolates code with dependencies on other application layers or frameworks. With just a few mouse clicks, you can generate suites of tests against code that previously may have been difficult or impossible to test.

Tonight I'll be giving a presentation on these technologies at the Nashville .NET User Group. For anyone who can't make it you can watch and discuss it in my Google Hangout. I'm hoping to post a video of the presentation to this blog within the next couple weeks. I'll also be giving a similar presentation and Code PaLOUsa on March 17th. Below are links to the demo solutions and Prezi used in the presentation.

Presentation on Prezi
Using Moles to Mock DateTime (Y2KBug.zip)
Using Moles to Stub Interfaces (MolesDemo.zip)
Using PEX to Generate Parameterized Unit Tests (PEXDemo.zip, PEXDemo-Result.zip)