title: Injecting a session variable into an IService using Ninject (ASP.NET MVC)
body: <p>I have a decent size web app that I want to make multi-client.  So at the minute I have a User table and my plan is to add a ClientId field to that table and then I can restrict users to only see the data for the client they belong to.</p>
  
  <p>In an ideal world, I'd like to try to bake the security for this in at the lowest level, so that it's difficult to accidentally create a feature that would cause a client to see another client's data.  So when I'm consuming services in the controllers, instead of having to pass the clientId everytime:</p>
  
  <pre><code>var messages = _messageService.GetMessagesByType(clientId, type);
  </code></pre>
  
  <p>It's automatic:</p>
  
  <pre><code>var messages = _messageService.GetMessagesByType(type);
  </code></pre>
  
  <p>I'm using Ninject to inject my services into the controllers:</p>
  
  <pre><code>    public static void RegisterTypes(IKernel kernel)
      {
          kernel.Bind&lt;IMessageService&gt;().To&lt;MessageService&gt;();
      }
  </code></pre>
  
  <p>My thought process at the moment, is to store the current user's clientId as a session variable and then somehow inject it into the IServices before they're consumed in the controllers.  </p>
  
  <p>However, I assume the RegisterTypes method is called once on App_Start, so how would I go about injecting it when an action is called?  Or is there a better approach to what I'm trying to acheive?</p>