I am using MVC3, I have several controllers based on various repositories, 1 in my repository of HTC References Depending on the session. To use the Windsor-Castle IOC, I have created the interface for each of our repositories.
How can I give the current session object to the repository it needs?
I used to be able to do this and "Resolve" could keep the necessary reserves for that time with the session, which I am not in the latest version (2.5.3 February 2011) Could:
secure override function GetControllerInstance System.Web.Mvc.IController Dim Match IController 'as 1 (byVal requestContext System .Web.Routing.RequestContext, as the _ ByVal controllerType System.Type) or more components New Hashtable deps.Add ("session", HttpContext.Current.Session) I F = container.Resolve (controllerType, deps) The recessive match termination function can be added as a (possible) dependency, the dim-deps, the session may be required, thanks, Vincent < / P>
Look closely at your design when you view it functionally, your repository is actually on session Does not depend on all, but in some sessions you store in the session. Create an abstraction on those things that you want to remove from the session and the repositories depend on such an abstract. For example:
Public Interface IUserProvider {int GetCurrentUserId (); } Some repositories of the public category: ISOM Registry {Private Readonly IUserProvider userProvider; Public SomeRepository (IUserProvider userProvider) {this.userProvider = userProvider; }} Now you can create the following implementation of that abstract:
private class HttpSessionUserProvider: IUserProvider { Public int GetCurrentUserId () {Return (int) HTTP Contex Current session ["userid"]; }} You can register this solid type in your IoC configuration.
This is better, because you do not want to go to your store directly depending on the HTTP session it tests hard and makes reliance between your repository and a specific presentation technique.
Comments
Post a Comment