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
About Windsor Castle
Windsor Castle - 5 Things you never knew - TheTrainline Blog
Read MoreWindsor Castle Tea
Get a real taste of British history as you wander through the historic castle of Windsor. It has been a royal home for over…
Read More