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 751633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:41:21+00:00 2026-05-14T14:41:21+00:00

Consider the following two scenarios: //Data Contract public class MyValue { } Scenario 1:

  • 0

Consider the following two scenarios:

//Data Contract
public class MyValue
{
}

Scenario 1: Using a static helper class.

public class Broker
{
    private string[] _userRoles;

    public Broker(string[] userRoles)
    {
        this._userRoles = userRoles;
    }

    public MyValue[] GetValues()
    {
        return BrokerHelper.GetValues(this._userRoles);
    }
}

static class BrokerHelper
{
    static Dictionary<string, MyValue> _values = new Dictionary<string, MyValue>();
    public static MyValue[] GetValues(string[] rolesAllowed)
    {
        return FilterForRoles(_values, rolesAllowed);
    }
}

Scenario 2: Using an instance class.

public class Broker
{
    private BrokerService _service;

    public Broker(params string[] userRoles)
    {
        this._service = new BrokerService(userRoles);
    }

    public MyValue[] GetValues()
    {
        return _service.GetValues();
    }
}

class BrokerService
{
    private Dictionary<string, MyValue> _values;
    private string[] _userRoles;

    public BrokerService(string[] userRoles)
    {
        this._userRoles = userRoles;
        this._values = new Dictionary<string, MyValue>();
    }

    public MyValue[] GetValues()
    {
        return FilterForRoles(_values, _userRoles);
    }
}

Which of the [Broker] scenarios will scale best if used in a web environment with about 100 different roles and over a thousand users.

NOTE: Feel free to sugest any alternative approach.

  • 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-05-14T14:41:21+00:00Added an answer on May 14, 2026 at 2:41 pm

    You can mess up threading using either static or instance classes. However, the key to getting threading right is to ensure that two threads don’t try to access the same resource at the same time.

    With static classes, by definition there’s only one copy of it around that all threads need to share nicely.

    With instance classes, you CAN create one instance per thread. If you ensure that each thread only accesses it’s own instance, AND that the instance properties and methods don’t in turn access other shared resources, they should be thread safe.

    In your case, I don’t see anything being changed in the classes after initialization. If you ensure you initialize your static classes in a thread safe manner (seems to be the case here), the static variant should be thread safe (since read-only access to variables) and will be a bit faster because you don’t have the overhead of creating and disposing instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To paint a scenario, consider the following logic-omitted-Service public class Service { private Validator
Consider the following two FFI structs: class A < FFI::Struct layout :data, :int end
consider the following two pieces of code: public static Time Parse(string value) { string
Please consider the following two entities: @Entity @Table(name = PROFILE) public class Profile extends
Consider the following scenario We have a simple database that involves two entities: user
Currently ive got some reference counted classes using the following: class RefCounted { public:
The problem is best explained by example, consider the following two models: class Topping(models.Model):
Consider the following two Java classes: a.) class Test { void foo(Object foobar) {
Please consider the following scenario, There are two web applications App1 & App2. A
Consider the following two relations: @Entity class Foo { @Id id; @ManyToMany @JoinTable(name =

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.