Something Like:

foreach(var client in listOfClients)
{
    For<NHibernate.Cfg.Configuration>()
        .Singleton()
        .Use(ctx=> new MyClientConfiguration(client.ConnectionString))
        .Named(client.Name);
    For<NHibernate.ISessionFactory>()
        .Singleton()
        .Use("SessionFactoryFuncOverload_"+client.Name,ctx=> ctx.GetInstance
<NHibernate.Cfg.Configuration>(client.Name).BuildSessionFactory())
        .Named(client.Name);
    For<NHibernate.ISession>()
        .Singleton()
        .Use("SessionFuncOverload_"+client.Name,ctx=> ctx.GetInstance<
NHibernate.ISessionFactory>(MagicStaticThing.GetClientNameForCurrentUser()).
OpenSession())
        .Named(client.Name);
}
For<IRepository>.Use<Repository>();


         


On Tuesday, December 22, 2015 at 6:23:09 AM UTC-5, Mike Duran wrote:
>
> I am creating a self-hosted ASP.Net webapi service that will have to 
> access 2 different databases.  
>
> The first is like a master database, it will always be the same database.  
>
> The 2nd would be like a customer database.  This could be different for 
> each request that comes into the service.  I can get the database id from 
> the request...but how to I handle the session management.  I understand I 
> should only create the session factories once...but how to I get the 
> correct session into my repositories.
>
> I'm using structuremap for my IOC container, ASP.net webapi is self-hosted 
> using topshelf. 
>
> Thanks.
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to