asp.net mvc - Get the HttpContext.Current upon dependency Resolution Unity -
how httpcontext.current in unityconfig? turns out null on upon start of application. need have current url of application upon dependency resolution. here goes code
public static void registertypes(iunitycontainer container) { // note: load web.config uncomment line below. make sure add microsoft.practices.unity.configuration using statements. // container.loadconfiguration(); //this null var http = httpcontext.current; container //add additional constructor support hosthelper of current set .registertype<idatacontextasync, oepdatacontext>(new perrequestlifetimemanager(), new injectionconstructor(hosthelper.getconfiguration())) .registertype<iunitofworkasync, unitofwork>(new perrequestlifetimemanager()) .registertype<irepositoryasync<menu>, repository<menu>>() .registertype<imenuservice, menuservice>(); // todo: register types here // container.registertype<iproductrepository, productrepository>(); }
Comments
Post a Comment