Giter VIP home page Giter VIP logo

fels-rohit / unitofworkwithmultipledbcontext Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raghav-rosberg/unitofworkwithmultipledbcontext

0.0 2.0 0.0 32.16 MB

An MVC 5 and Web API 2 application with Automapper, EF 6, repository pattern, dependency injection and IOC using Autofac which uses one unit of work to deal with multiple dbcontexts with Async functions

C# 38.41% CSS 0.67% ASP 0.11% PowerShell 60.81%

unitofworkwithmultipledbcontext's Introduction

Unit Of Work With Multiple DBContexts

A MVC 5 application with Automapper, EF 6, repository pattern, dependency injection using Autofac which uses one unit of work to deal with multiple dbcontexts with Async functions.

Features:

  • Entity Framework 6
  • MVC 5 Web App
  • Async MVC 5 Web App
  • MVC 5 WepAPI 2
  • Dependency Injection and IOC using Autofac
  • AutoMapper
  • Unit Of Work with multiple DBContexts
  • Generic Repository with Async functions
  • Service layer with Async functions
  • Code First approach
  • Power of repository extensibility
  • NUnit with Async Tests
  • Moq

Instructions:

  • Please alter connection strings in the application's webconfig file.
  • Go to package manager console -> select UoW_MultipleDBContext.Data and execute the command 'update-database -verbose'.

This application's design pattern overcomes most of the redundant code while creating repositories and resolves a unit of work with multiple Dbcontexts.

Dos while creating repositories:

  • Create a generic repository class and generic repository interface which exposes common functions to each entity.
  • Create individual repository classes which extends generic repository with additional functions of its interface where ever it is required.
  • Initialize a generic repository's local DBContext object through its constructor.
  • Set this DBContext's entities-set in to the generic repository's local entities-set object.

Don'ts while creating repositories for unit of work:

  • Do not create multiple repository interface and repository classes for all the repositories which is not required.
  • Do not associate or inject your DBContext object to your generic repository class. Get the DBContext reference from Unit of work class.

Good way of designing your service layer:

  • Create one service class for one controller.
  • Have an individual interface for each service class - Which helps customizing functions related to its service.
  • Inherit generic repository interface to the service interface - Which forces the service class to expand all the methods in generic interface (optional).
  • Inject unit of work objects corresponding to its DBContext in the service constructor.
  • Access repositories through Unit of Work object.
  • Commit all the transactions corresponding to a DBContext once with its Unit of Work object.
  • In the controller inject only its related service object and call its functions for further operations.

Hope this design pattern helps. Please let me know if i had missed anything and any suggession to improve this design is welcome.

-- Raghav

unitofworkwithmultipledbcontext's People

Contributors

raghav-rosberg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.