c# - working with entity and repository -


let's have ibookrepository. , besides ravendb want add sqlserver implementation of ibookrepository called sqlserverrepository.

what proper way create implemenation of interface having db context in mind. should pass dbcontext parameter inside sqlserverrepository constructor , populate class member dbcontext work db?

public class sqlserverbookrepository : ibookrepository {    private mydbcontext _db;    public sqlserverrepository(mydbcontext db)    {       _db = db;    }    public void addbook(book b){       // adding book context       _db.savechanges();    } } 

i'm asking proper way? there better way? should store dbcontext in same layer repository, dao layer, how it?

i manage datacontext lifetime outside of repositories. use ioc tool (usually structuremap) scope context httpcontext. inject instance of datacontext repositories.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -