Hello folks.
This is my first post. I hope is an interesting one.
I have this registration....
public class NHibernateFacility : AbstractFacility
{
protected override void Init()
{
Kernel.Register(
Component.For<ISessionFactory>().UsingFactoryMethod(() =>
EntityManager.SessionFactory).LifestyleSingleton(),
Component.For<ISession>().UsingFactoryMethod(EntityManager.SessionFactory.OpenSession),
Component.For<IEntityManager>().ImplementedBy<EntityManager>().LifestyleSingleton());
}
}
Here is my EntityManager Class....
public class EntityManager : IEntityManager
{
public static Func<Assembly[]> GetAssemblies = () => new
Assembly[0];
public EntityManager()
{ }
private static readonly Lazy<ISessionFactory> NHibernateFactory =
new Lazy<ISessionFactory>(() =>
{
var config = Configure();
var factory = config.BuildSessionFactory();
return factory;
});
private static Configuration Configure()
{
var config = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2000.ConnectionString(c
=> c.FromConnectionStringWithKey("FamilyDerm")).ShowSql())
.Mappings(m =>
{
m.FluentMappings.AddFromAssemblyOf<EntityManager>();
m.HbmMappings.AddFromAssemblyOf<EntityManager>();
}).BuildConfiguration();
return config;
}
public static ISessionFactory SessionFactory { get { return
NHibernateFactory.Value; } }
public ISession CurrentSession
{
get { return SessionFactory.GetCurrentSession(); }
}
}
Now, this works like a charm. BUT, i have a little problem. Our company
operates in two states, and they have the same schema (different data of
course) sitting in two different sql servers. Our employees must select a
region before they start using the system. They way we manage it right now
is using a SessionVariable["REGION"] that we check right before a
Controller (.NET MVC) is executed and we adjust the connection string
dynamically (our employees can hot swap regions once they are in the
system). This works... but smelly like fish market. Plus, we want to take
advantage of NHibernate (we are using right now our own DBAccessor class
with plain ADO.NET because of SQL 2000).
What should i do here? Should I create a second SessionFactory Property
that would call NHibernateFactory with a parameter to distinct the
connection String? Should i register TWO EntityManagers and add a
constructor value for each entitymanager and also set a Name to each
component, so i can use a IHandlerSelector and call them using this
Name/Key?
What would be your approach to this?
Thanks
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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 http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.