asp.net mvc - How do I inject an HTTP-Request-specific object into my Unity supplied object? -


for example, store "current user" in session. business-layer object being instantiated unity. how make business-layer object aware of "current user"?

you should hide "current user" behind abstraction:

public interface icurrentuser {     string name { get; } } 

this abstraction should defined in business layer , need create asp.net specific implementation place in composition root:

public class aspnetcurrentuser : icurrentuser {     public string name     {         { return httpcontext.current.session["user"]; }     } } 

now business-layer object can depend on icurrentuser interface, , in unity can register implementation follows:

container.registertype<icurrentuser, aspnetcurrentuser>(); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -