Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:19:25+00:00 2026-06-01T21:19:25+00:00

I’m writing a site in MVC3, using Entity (linked to Postgres, but not sure

  • 0

I’m writing a site in MVC3, using Entity (linked to Postgres, but not sure that part is relevant.

A user is part of a number of “leagues”, and creates an “event” against one of those leagues.

there will be other users that have access to that league, and when they go to view a list of the events, I need the list to display only those “events” that are part of “leagues” they have access to.

Now there are numerous ways that this could be achieved, but I’m looking for the most elegant and widely accepted to be “the correct way”.

Currently the User -> league relationship is held in the same place as the rest of the data, therefore I can just filter by the leagues without a problem. My issue is that I’m not sure whether or not I should be accessing the HttpContext to get the userId within the repository layer to do the Filtering.

If I don’t do the above, I was considering using the RoleMembership functionality and make Leagues, Roles, and then there is built in functionality to do it.

The question is, what’s the best practice for filtering result data by user Access in MVC3/Entity?

Blogs/Tutorial links are preferred, but full answers may also be accepted…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:19:27+00:00Added an answer on June 1, 2026 at 9:19 pm

    I definitely do not think the repository should be invoking the HttpContext object. I’d recommend following the dependency-injection pattern for this application. In this scenario, there are three interfaces– one is the data-access interface (the repository); another is the provider of filtered data to your view (the view model); and a third is the provider of role information (the role provider).

    So, the repository is stand-alone; the role provider has a dependency (I gather from your question) on HttpContext; and the view model has a dependency on both the repository and the role provider. I would emphasize that you write a dependency wrapping of any HttpContext methods you’re planning to use, so as to facilitate testing.

    There’s a fairly extensive tutorial on dependency-injection and MVC, on MSDN: http://msdn.microsoft.com/en-us/gg618491

    To illustrate:

    public interface ILeagueRepository 
    {
        IEnumerable<League> All;
    }
    
    public interface ILeaguesProvider
    {
        IEnumerable<League> GetUserLeagues(string Username);
    }
    
    public class LeaguesProvider : ILeaguesProvider
    {
        public LeaguesProvider(ILeagueRepository repository)
        {
             // ...
        }
        public IEnumerable<League> GetUserLeages(string Username)
        {
            return _repository.All.Where(league=>league.User == Username);
        }
    }
    
    public ActionResult LeaguesController
    {
        public LeaguesController(ILeaguesProvider providerDependency, IRoleProvider roleDependency)
        {
            IEnumerable<League> leagues = providerDependency.GetUserLeagues(roleDependency.GetCurrentUser());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.