c# - EF AND MVC - Passing Repositories through controllers -
i have mvc app uses entity framework orm. working expected - however, on every new controller initialise new repository
public acontroller() : this(new arepository()) public acontroller(ia _a) { this.m_a = _a }
but when initialising new repository, needs entites database , in 1 repository, needs on 5000+ entities
list<object> ob = m_a.entity.tolist(); // has on 5000+ items
the obvious problem when user posts or gets these controllers, going time, , of course, initialising new repository on controller, slowing downwards performance , cannot utilize local
cache speed things up.
is there way can send repository through each controller or anyway can speed ef fetching?
thanks
you instantiate repository using dependency injection instantiate singleton object. if don't plan utilize di container, create static instance in project can seen/shared in controllers:
private static imyrepository _instance; public imyrepository repository { { if (_instance == null) { _instance = new somerepositoryobject(); } homecoming _instance; } }
in case, because of initialization, create method rather property , after object created, phone call method load 5000+ objects.
c# asp.net-mvc entity-framework
No comments:
Post a Comment