Introducing generator-efrepo for yeoman


In this blog post I will show you how to use the new generator-efrepo that I wrote couple of days ago. The idea behind this Yeoman generator is to automate some of the boaring tasks while starting on a brand new project such as,

  • Creating Model classes
  • Adding EntitiFramework NuGet package
  • Creating EntitiFramework Context class
  • Creating Repositories and UnitOfWork on top of your context
  • During public demos you have to create multiple class and integrate EF for data access

This blog post assumes that you have basic idea about the Yeoman generator itself along with EntityFramework CodeFirst and Repository/UnitOfWork design patterns. If not,please do some basic reading on here before you start using this generator. Alright, let's get started.

Installing Yeoman(If you do not have it already)

Then make a directory where you want the Yeoman generator to create the EntityFramework project. Navigate to that folder in your command line tool.Make sure you have nodejs and npm installed on your system by runing following commands.

Check nodejs $ node -v

Check npm $ npm -v

Install Yeoman

$ npm install -g yo


ToDo Manager With AngularJS and Web API Part V


Okey,So far in last 4 posts, we have a basic AngularJS project with CRUD opderations on one business entity, Project. If you have missed any of them please follow the below links.

In this post we will do some refactoring to see how we can extract the data access logic into some sort of a service.

Creating the Service

Let's create the new JavaScript file named ProjectService.js in the services folder.


ToDo Manager With AngularJS and Web API Part IV


So far in last 3 posts, we have created a basic AngularJS application that brings data from server and displays that as list. If you have missed them following are the direct links.

In this post we will extend the application to allow Create/Update/Delete from the AngularJS UI.

Creating the ADD button

<input ng-show="!vm.ShowForm"
       ng-click="vm.ShowForm=!vm.ShowForm"
       type="button" class="btn btn-primary" value="Add Project" />

As you can see it's simple input button but it is manipulating the property from the scope called ShowForm. We will use this variable to control the visibility of the form. Let's add this property along with one other object and event in our Controller.


ToDo Manager With AngularJS and Web API Part II


In the previous post we started on the journey to create AngularJS ToDo Manager application. So far we have a basic Projects setup along with the initial database desing. In this post we will apply Repository and UnitOfWork pattern on our EntityFramework context class so when our API needs to access data we can work with single interface of UnitOfWork.

So let's get started.

Create Repositories and UnitOfWork Interface and implementations

First thing first let's create our BaseRepository and interface for that.

public interface IBaseRepository<TEntity> where TEntity : class
{
    IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null,
                             Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
                             string includeProperties = "");
    TEntity GetByID(object id);
    void Insert(TEntity entity);
    void Delete(object id);
    void Delete(TEntity entityToDelete);
    void Update(TEntity entityToUpdate);
    void Reload(TEntity entityToUpdate);
}

As you can see it is a pretty standard repository that I have obtained over the period of time from different tutorials available on line. I will also provide the implementation of this repository in downloadable sample.

Next, let's create a UnitOfWork Interface and implementation for that interface as well. Following is the screen shot of the implementation. It only really has one method Save but it also exposes individual repositories that we can access through UnitOfWork instance.