Unity with asp.net mvc, passing parameters with property injection -


i inserting dependency in mvc controller shown below:

public class homecontroller : controller {     [dependency]     public iproxyservice proxyservice { get; set; } } 

in global.asax, type registered using

unitycontainer _container = new unitycontainer(); _container.registertype<iproxyservice, systemproxyserviceex>(); 

now, need pass few parameters systemproxyserviceex constructor. these include values stored in session variable(httpsessionstatebase session) stored during authentication. how make happen?

the common thing wrap in class , inject based on interface. instance:

// interface lives in service or base project. public interface iusercontext { string userid { get; }

    // other properties }  // class lives in web app project  public class aspnetusercontext : iusercontext {     public string userid     {         { return (int)httpcontext.current.session["id"]; }     }      // other properties } 

now can make systemproxyserviceex take dependency on iusercontext. last step register it, of course easy:

_container.registertype();


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -