Programming Stuff

Creating Storefront in ASP.NET 5

00.logo

Framework .NET 3.5                                 =>                                 Framework .NET 4.6

C# 3.0                                =>                                 C# 6.0

MVC 2.0                                =>                                 MVC 6.0

                 Linq to SQL                                =>                                Entity Framework 7.0

MSTest                                =>                                xUnit

 

What a great way to learn Visual Studio 2015 by Redoing a well-designed and well-known example of an e-Commerce Solution created by Rob Conery.

25 Videos (ASP.NET MVC Storefront Starter Kit): http://www.asp.net/mvc/videos/mvc-1/aspnet-mvc-storefront/aspnet-mvc-storefront-part-1-architectural-discussion-and-overview

[Part #1] Architectural Discussion and Overview

The initial architect of the solution was made here and I found a couple of challenges:

* TDD: The new Visual Studio doesn’t allow you to create a .Test solution as easier as before, instead you now have to create your own ASP.NET Class Library  and add the xunit  references. You will need 3 packages: xunit , xunit.runner.aspnet, and   xunit.runner.visualstudio .

More info about TDD:  http://stackoverflow.com/questions/29089172/tdd-in-the-new-visual-studio-vnext-2015

01.Testing

* Class Diagram is not available by Visual Studio and since this is not required, I will let the UML class diagram out of my implementation. (I found a way to implement Class Diagram using VS Ultimate: http://s.ch9.ms/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012-Improving-architecture-through-modeling)

UPDATE 4/4/2015

[Part #2] The Repository Pattern

In this part, the Repository pattern was implemented for Catalog. They were basic steps until I found an issue when I was introducing the System.Linq.IQueryable  interface in the Class Libraries. This makes VS unhappy and make display some warnings saying that the library was available for ASP.NET 5.0  but not for ASP.NET Core 5.0  therefore the project didn’t want to build.

Error IQueryable

I was able to fixed the issue by removing ASP.net Core 5.0  from framework section in the class projects (Data, Service, Test).

More info about build-problems:  http://stackoverflow.com/questions/27844574/vs-net-2015-project-wont-build

Remove aspnetcore50

Finally, the application built and passed all the tests.

Repository Tests

[Part #3] Pipes and Filters

The changes in this step is very straight forward. It was about implementing Pipes and Filters using extension methods in a IQueryable collection. Technology speaking, I didn’t find any conflicts at all. The author, did some re-designs, such as, removing ProductReview , re-creating the  Product  class and other few other changes.

UPDATE 4/11/2015

[Part #4] Linq to Sql (EF7)

The main idea is creating a spike test where we can proof that the assumption about database access will work.

NOTE: Since there were conflict using IQueryable in part2, Initially, I decided to remove ASP.NET Core 5.0 but now that I am adding EF 7.0, I really need the framework ASP.NET Core 5.0, so I added it back and I fixed the conflict with IQueryable by adding a ASP.NET Core 5.0 dependency. http://davidzych.com/creating-an-asp-net-5-class-library-with-vim/

In order to implement EF 7.0, I need 3 things: add 2 libraries EntityFramework.SqlServer, EntityFramework.Commands  and add the ef  command. The first library is used for implementing EF using SQL Server database, Also other libraries available are: In Memory or SQL Lite. The Second library is to execute migration’s commands such as add, apply, etc. In the beginning I was having hard time implementing DbContext because I was using the EF version 7.0.0-beta5 , at the end, I decided use earlier version 7.0.0-beta3  that works just fine.

After read and tried a lot of EF7 implementations from the internet, none of them works for my Class library, but I finally found one of the most clear and well-explained guide about implementing EF7, and then I followed each step and I made it worked:  https://www.youtube.com/watch?v=hHuWmMHJb4M

This code have to be re-factor for a real world application, here my concerns:

* I cheated a little bit in this part by making the DB code-first model similar to Linq-to-Sql old framework creating duplicates models. A realistic approach will take advantage of the EF7 by reusing the same model and implementing lazy loading.

* The db-context is disposable and right now the code is not managing that. If I managed the db-context with using  in  SqlCatalogRepository the code will break, because the connection will be close before it reaches  ToList().

* And finally, it doesn’t support transactional operations.

 

Pic. Migration Commands:

migration-add-apply

Pic. Database:

StorefrontDB

Pic. Integration Test:

CatalogIntegrationTest

(To be continue…)

 

Source:

Octocat
 https://github.com/jaider/Storefront2015

News: