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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:43:24+00:00 2026-05-22T23:43:24+00:00

What is the best design for this scenario? I have different Object types: User

  • 0

What is the best design for this scenario?
I have different Object types: User, Channel, MessageBox, UserGroup, etc.
User and Channel can have permission on other objects. For example User has the following enum defined as its permissions for MessageBox:

CanRead,
CanWrite,
CanDelete,
...

Other enums are defined for User as the owner of other object types.

Also, Channel has different enum values on these objects. For example, consider Channel as the owner and MessageBox as the object:

CanDispath
CanRetrieve
...

All the permissions are saved and retrieved from a specific table in database using bitwise comparison:

OwnerID........OwnerType........ObjectID........ObjectType........AccessLevel  
  1              User              10           MessageBox            38     
  5             Channel            12           MessageBox            18  

Now in code behind, What’s the best way to implement permission classes?

1- Define PermissionManager, UserPermissionManager, ChannelPermissionManager classes separately from each other. Other classes just call PermissionManager like:

if (new PermissionManager.HasAccess(CurrentUser,  
                                    CurrentMessageBox, 
                                    UserPermissions.CanReadMessages))  

Then PermissionManager decides what class this is related to based on the OwnerType (UserPermissionManager or ChannelPermissionManager) and calls its HasAccess method. This way, PermissionManager.HasAccess is always being called and I think it can make the code more maintainable and extensible. This is my preferred solution but since PermissionManager, UserPermissionManager and ChannelPermissionManager refer to the same context, I think there should be a hierarchy or possibly an interface so these 3 classes become more integrated. But I don’t know how to relate them together.

2- Define IPermissionManager interface and implement UserPermissionManager and ChannelPermissionManager from it. Add PermissionManagerTypes enum. Create a factory class and call Managers like:

IPermissionManager UserManager =   
    PermissionFactory.Create(PermissionsManagerTypes.User);
if (UserManager.HasAccess(CurrentUser,  
                          CurrentMessageBox, 
                          UserPermissions.CanReadMessages))  

This is a kind of failed try to relate classes together. But I thought It’d be good to mention it here to let you know what I’m trying to achieve.

P.S. I cannot define classes as static since they need to have a private variable of type ObjectContext (Entity Framework).

Is there a better solution to achieve this?
Thank you and Apologies for the very lengthy question.

  • 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-22T23:43:25+00:00Added an answer on May 22, 2026 at 11:43 pm

    Well, this is pretty hard to answer. You could try to create a base interface IPermission;

    interface IPermission<TOwner>
    {
    }
    

    Then you implement this interface for the types you want to be able to own a permission.

    class UserPermission : IPermission<User>
    {
        public UserPermission(CustomerPermissionType type)
        {
            // Store the type
        }
    }
    
    class ChannelPermission : IPermission<Channel>
    {
        public ChannelPermission (ChannelPermissionType type)
        {
            // Store the type
        }
    }
    

    Now you need an interface that provides permissions for specific objects.

    interface IPermissionProvider
    {
        bool HasPermission<TOwner>(IPermission<TOwner> permission, TOwner owner, object target);
    }
    

    At this point you have the basic functionality to query for permissions. The problem is how to manage the different handling for User and Channel permissions. You could implement something like this:

    class PermissionDispatcher : IPermissionProvider
    {
        public void RegisterPermissionProvider<TOwner>(IPermissionProvider     permissionProvider)
        {
            // Store it somewhere
        }
    
        public IPermissionProvider GetPermissionProvider<TOwner>()
        {
            // Look up a permission provider that is registered for the specified type TOwner and return it.
        }
    
        bool IPermissionProvider.HasPermission<TOwner>(IPermission<TOwner> permission,     TOwner owner, object target)
        {
            IPermissionProvider  permissionProvider = GetPermissionProvider<TOwner>();
            return permissionProvider .HasPermission<TOwner>(permission, owner, target);
        }
    }
    

    The last step would then be to create specific implementations of IPermissionProvider for User and Channel and register them to the PermissionDispatcher at the startup of your application / service.

    The usage would be as simple as this:

    void foo()
    {
        IPermissionProvider permissionProvider = ... the dispatcher, could be a singleton ...;
        User user = ...;
        MessageBox messageBox = ...;
        UserPermission userCanReadPermission = new UserPermission(UserPermissionType.CanRead);
        bool hasUserCanReadPermission = permissionProvider.HasPermission(userCanReadPermission, user, messageBox);
    

    }

    Something like this will be the only way to solve this without taking a dependency on permission handling in your domain types. Nevertheless I’m absolutely sure this is no perfect solution.

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

Sidebar

Related Questions

I'm looking for ideas on the best way to refactor this scenario (better design,
In JavaScript, the this operator can refer to different things under different scenarios. Typically
How would the following scenario best be implemented: There is a standardized user interface
I'm not sure the best way to design this, so here goes: I'm tracking
I have an object in C# like this: private ClassWidget { public int ID;
I have a scenario where I am designing a system for a retailer. This
I am struggling to choose the perfect design pattern for this scenario : When
Scenario. I have a library shelf, library, user, application tables in the database. One
Whats the best design pattern to use for LINQ and type tables that exist
What is the best design decision for a 'top-level' class to attach to an

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.