Would the following strategy suit your intentions:

1) Create a database and configuration per tenant:
<activerecord>
  <config tenant="cust1">...</config>
  <config tenant="cust2">...</config>
  <config tenant="cust3">...</config>
</activerecord>

2) Choosing tenant when starting a SessionScope:
string tenant = "cust1"; // rather get this from logon or something
using (var scope = new SessionScope(tenant)
{
  // all here uses database for cust1
}

I had this in mind as an idea, but didn't implement it so far.

-Markus

2010/7/10 Markus <[email protected]>:
> Thanks for the hint. I had a look at the class, but it's not exactly
> what I am looking for.  Furthermore, the class is commented with
> 'Still very experimental and it's not bullet proof for all
> situations' (AR V2.0.0.0)
>
>
> On 8 Jul., 23:47, Henry Conceição <[email protected]> wrote:
>> Check the DifferentDatabaseScope.
>>
>> On Jul 8, 4:51 am, Markus <[email protected]> wrote:
>>
>> > Hi all!
>>
>> > I'm developing a multi-tier application that will support multiple
>> > tenants. Each tenant's data will be isolated in a separate database.
>> > I'm looking for an elegant way to set the connection string during
>> > runtime depending on the tenant's identifier (e.g. ID, name ...). My
>> > idea is to use a custom ConnectionProvider that returns the
>> > appropriate tenant-specific connection string, something like that:
>>
>> >     public class MyConnectionProvider : DriverConnectionProvider
>> >     {
>> >         private object tenant;
>>
>> >         public MyConnectionProvider(object tenant)
>> >         {
>> >                 this.tenant = tenant;
>> >         }
>>
>> >         protected override string ConnectionString
>> >         {
>> >             get
>> >             {
>> >                 return BuildMyTenantConnectionString()
>> >             }
>> >         }
>> >     }
>>
>> > On the other side I have my business methods that access the database
>> > using AR, say for example:
>>
>> > public IList GetCustomers(object tenant)
>> > {
>> >       return Customer.FindAll();
>>
>> > }
>>
>> > Now my question is how to inject/pass the 'tenant' parameter form my
>> > business method into my custom connection provider in order to access
>> > the data in the correct database? Are there any best practices? Or
>> > alternative solutions?
>>
>> > Thanks
>>
>> > Markus
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to