c# - dependency inversion in top class (main) -
i want create app in have these 2 classes, mainapp , model (in reality more, base , core of problem). mainapp starting class. want apply dependency inversion mainapp doesn't have rebuild each time model changes (well, because practice). can't this:
mainapp - - - > imodel ^ | | model because i'd have create model in mainapp anyway because it's start of app, redundant.
i thinking shifting contents of mainapp class , use mainapp factory mainappcontents , model, this:
mainapp -------------> model | | | | v v mainappcontents - - - > imodel is correct approach , mean start of designed app factory?
it sounds asking way enable late binding. programming interface first step, , doing that.
the next step map interface concrete class. easiest way di container. main method might this:
static void main() { var container = createcontainer(); imodel model = container.resolve<imodel>(); // use model... } i omitted implementation of createcontainer helper method on purpose because selecting di container different question.
all mainstream di containers .net support late binding, enable implement imodel in assembly. imodel interface should stay consumer (main).
Comments
Post a Comment