Skip to content
Muhammad Rashed Otahbashi edited this page Jun 30, 2015 · 8 revisions

Welcome to the EnterpriseFramework Welcome to Enterprise Framework, this framework is to help build enterprise solutions using Asp.Net MVC with Repository Pattern and Unit of Work Patter all together easily

Repository Pattern This pattern is to encapsulate communicating with the data source with ability to use real or fake infrastructure classes, enterprise framework enables you to use entity framework easily with ability to use generic or custom repositories

You can build your app with three projects : Core - Data - Web

you can reference them using nuget commands

  1. The Core project: add your nuget package using command : Install-Package EnterpriseFramework.Core this project contains your models for example this class:

    public class Account: BaseModel { public string Code { get; set; } [Required] public string Name { get; set; } public bool IsParent { get; set; } }

  2. Data project: add your nuget package using command : Install-Package EnterpriseFramework.Data

in the Data project we can add the following : OurDbContext , OurFakeContext , OurUnitOfWork , Our Custom Repository.

public class AccountingDbContext  : BaseDbContext , IDbContext
{
    public AccountingDbContext()
    {
        Database.SetInitializer<AccountingDbContext>
           (new DropCreateDatabaseIfModelChanges<AccountingDbContext>());
    }
    DbSet<Account> Accounts { get; set; }
    DbSet<Journal> Journals { get; set; }
    DbSet<JournalAccount> JournalAccounts { get; set; }
}

public class AccountingFakeContext : FakeDbContext<AccountingFakeContext >, IDbContext
{
    FakeDbSet<Account> Accounts { get; set; }
    FakeDbSet<Journal> Journals { get; set; }
    FakeDbSet<JournalAccount> JournalAccounts { get; set; }
}

///Now with standard repositories

public class AccountingUnitOfWork<TContext> : BaseUow<TContext>
    where TContext : IDbContext
{
    public IDataRepository<Account> Accounts { get { return GetStandardRepository<Account>(); } }
    public IDataRepository<Journal> Journals { get { return GetStandardRepository<Journal>(); } }
    public IDataRepository<JournalAccount> JournalAccounts { get{ return GetStandardRepository<JournalAccount>(); } }
}
  1. Web project: add your nuget package using command : Install-Package EnterpriseFramework.Web

Now in the Web project we can add controller like the following

public class AccountController : BaseMasterController<Account 
            , AccountingUnitOfWork<AccountingDbContext>, AccountController >
{
    public AccountController() : base (new AccountingUnitOfWork<AccountingDbContext>())
    {
        GetRepository = uow => uow.Accounts;
        IndexViewName = "IndexName";
        Title = "Account Management";
    }
}

Now you have a full functional Insert / Update / Delete / List functions , but please note that you might need to create custom index in your view folder to customize the grid columns.

Enjoy! والحمدلله رب العالمين

https://www.facebook.com/profile.php?id=Muhammadrashedotahbashi https://eg.linkedin.com/pub/muhammad-rashed-otahbashi/50/529/947

Clone this wiki locally