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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:38:26+00:00 2026-06-02T09:38:26+00:00

I would like to ask your opinions regarding the way I handle MultiTenancy. Im

  • 0

I would like to ask your opinions regarding the way I handle MultiTenancy. I”m using MVC3 (switching to MVC4) and EF as my backend. I’m using a single app, shared schema MultiTenancy. Below is the code:

public abstract class Service<T> where T : Entity
{
    private Repository<T> _repo;
    public Service()
    {
        _repo = new Repository<T>();
    }

    public bool Authenticate(int id)
    {
        //var companyInfo = _authorizationRepository.GetApiKey(apiKey);
        int tenantId = 0; // replaced by companyInfo using repository
        var entity = _repo.GetQuery(tenantId).Where(e => e.Id == id).First();

        if (tenantId != entity.TenantId)
            throw new ArgumentException();

        return true;
    }
}

public class EmployeeService : Service<Employee>
{
    private EmployeeRepository employeeRepository;
    public EmployeeService()
    {
        employeeRepository = new EmployeeRepository();
    }

    public Employee GetEmployeeById(int employeeId)
    {
        this.Authenticate(employeeId);
        return employeeRepository.GetById(employeeId);
    }
}

public class Entity
{
    public int Id { get; set; }
    public int TenantId { get; set; }
}

Of course DI will be there as well but for simplicity I removed them here (temporarily). I used Generics (feeling dirty about it) on the Service Layer since I’m having trouble on comparing the TenantId with the correct Entity that will be passed on the class. I’m eyeing to recode this using FilterAttributes but I dont have any idea how to. How do you guys handle your multitenancy? Is the design have some crucial flaws that I may encounter on the long run? If you have some samples using FilterAttributes that would be a big help.

Thanks!

  • 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-02T09:38:31+00:00Added an answer on June 2, 2026 at 9:38 am

    We are building pretty big multi tenancy web app at the moment. Well it’s not so simple as it seems but once you build your architecture it’s straight forward. Our is deeply in development but you can check out the open source part in nanocms.codeplex.com (we haven’t uploaded the db jet butt we will in few days)

    Since this is a pretty wide question I’ll try to summarize some problems and solutions.

    First you need to identify tenant for each request. We have a global action filter that parses url and compares it with data in database. Of course you must cache all data so no calls to database are made. You must not save any of that in a cookie or session because user can visit more than one tenant at the time. I suggest that you put that data in HttpRequest Items so you do that only once in a request but still have that data available always.

    For authenticate users must be unique. You must think if you want to give some user different rights on each tenant. If so you must write your authenticate code and even attribute so you can check his role in current tenant. In our app when user authenticates we create session object. In object we have static methods that check for rights in tenant.

    I suggest you keep HttpRequest Items strongly typed. We have:

    public static int TenantID {
        get { return System.Web.HttpContext.Current.Items.Contains("TenantID") ? Convert.ToInt32(System.Web.HttpContext.Current.Items["TenantID"]) : -1; }
        set {
            if (!System.Web.HttpContext.Current.Items.Contains("TenantID"))
                System.Web.HttpContext.Current.Items.Add("TenantID", value);
            System.Web.HttpContext.Current.Items["TenantID"] = value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask your guidance on how to authenticate using email add/
I would like to ask your opinions on how the current log in user
Hello I would like to ask your help regarding javascript code, how do I
I am quite new about using Solr, but would like to ask your help.
I would like ask if there's a way to download an android layout from
I would like to ask the same thing than this question but using SWT:
Hello everybody :D I would like to ask for your help on this problem.
I use c#, linq and EF4 I would like ask your help. My question:
Greetings, I would like to ask if there's a way to block website(s) from
i would like to ask for your help since I'm having difficulty resolving this

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.