
Windsor Castle IoC
Look closely at your design. When you look at it functionaly, your repository doesn't really depend on the the session at all, but at some data you store in the session. Create an abstraction over the things you want to extract from the session and let the repository depend on such abstraction. For instance:
public interface IUserProvider { int GetCurrentUserId; } public class SomeRepository : ISomeRepository { private readonly IUserProvider userProvider; public SomeRepository(IUserProvider userProvider) { this.userProvider = userProvider; } }
Now you can create the following implementation of that abstraction:
private class HttpSessionUserProvider : IUserProvider { public int GetCurrentUserId { return (int)HttpContext.Current.Session["UserId"]; } }
You can register this concrete type in your IoC configuration.
This is much better, because you don't want to let your repository depend directly on the HTTP session. This makes testing harder and creates a dependency between your repository and a specific presentation technology.
Video on topic: Windsor Castle IoC



Share this Post
Related posts
Windsor Castle Dolls House
The largest, most beautiful and most famous dolls’ house in the world. Built for Queen Mary by the leading British architect…
Read MoreWindsor Castles
By Mike Glaeser The first challenge of this trip occurred even before I could land. My flight was delayed which put my 11:45…
Read More