i'm learning mvc in asp.net space. if want pass controller ctor parameter seems can create controller factory register mvc framework. see examples below , have wonder how mvc framework knows use factory when controller created?
public class customcontrollerfactory : icontrollerfactory { public icontroller createcontroller(system.web.routing.requestcontext requestcontext, string controllername) { ilogger logger = new defaultlogger(); var controller = new homecontroller(logger); return controller; } public system.web.sessionstate.sessionstatebehavior getcontrollersessionbehavior( system.web.routing.requestcontext requestcontext, string controllername) { return sessionstatebehavior.default; } public void releasecontroller(icontroller controller) { idisposable disposable = controller idisposable; if (disposable != null) disposable.dispose(); } } public class mvcapplication : system.web.httpapplication { protected void application_start() { registercustomcontrollerfactory (); } } private void registercustomcontrollerfactory () { icontrollerfactory factory = new customcontrollerfactory(); controllerbuilder.current.setcontrollerfactory(factory); }
so controller factory creates instance of homecontroller , passes specific logger object. default controller factory never used in application because of registering custom controller factory? have 2 factories now? default other controllers , specific 1 homecontroller? if how mvc know controller factory use? in application want many controllers taking different parameter types, how work?
i tried googling specific question couldn't find around it. found bunch of frameworks people use, want understand specific part of it. thanks!
you not need controller factory that. take @ asp.net mvc dependency injection. should basic overview, , find dependency injector able work asp.net mvc 2
Comments
Post a Comment