MultiSessionFactory is driving me crazy....

95 views
Skip to first unread message

Quicoli

unread,
Feb 7, 2012, 11:17:15 AM2/7/12
to uNhAddIns
Friends,

I'm trying to use 2 databases, CpBT, conform and configuration by
code. But when I try to get my IDao<> implementation, I get an error
saying my factory name is not registered. But, under debugging I see
my factory has a name! I'm lost. I really appreciate some guidance
about that. To make things clear, I would like to show what I'm doing
here:

- I have a class ConfigurationProvider inheriting from
DefaultMultiFactoryConfigurationProvider. In this class I have 2
methods which configure the 2 databases, and also, setting the factory
name, like this:

*** Any help is welcomed :)

private Configuration ConfigureProviderDb1()
{
var cfg = new Configuration();
cfg.SessionFactoryName(factoryName1);
// so, so...
return cfg;
}

private Configuration ConfigureProviderDb2()
{
var cfg = new Configuration();
cfg.SessionFactoryName(factoryName2);
// so, so...
return cfg;
}

So, I did an override in Configure() method like this:

public override IEnumerable<Configuration> Configure()
{
var result = new List<Configuration>(4);

result.Add(ConfigureProviderDb1());
result.Add(ConfigureProviderDb2());

Configuration = result;
return result.ToArray();
}

So, in my ServiceLocatorProvider.Initialize method I do:

var container = new WindsorContainer();
container.AddFacility<FactorySupportFacility>();
container.AddFacility<PersistenceConversationFacility>();

container.Register(Component.For<ISessionFactoryProvider>().Named(

sessionFactoryProviderComponentKey).ImplementedBy<MultiSessionFactoryProvider>());

RegisterSessionFactoryFor(sessionFactoryName1, container);
RegisterSessionFactoryFor(sessionFactoryName2, container);

container.Register(Component.For<ISessionWrapper>().ImplementedBy<SessionWrapper>());
container.Register(Component.For<IConversationFactory>().ImplementedBy<DefaultConversationFactory>());
container.Register(Component.For<IConversationsContainerAccessor>().ImplementedBy<NhConversationsContainerAccessor>());

container.Register(Component.For(typeof(DAO.IDao<>)).ImplementedBy(typeof(DAO.NhDao<>))
.Parameters(Parameter.ForKey("factory").Eq("${" +
GetSessionFactoryProviderKey(sessionFactoryName2) + "}")));


container.Register(Component.For(typeof(DAO.SistemaRI.IDao<>)).ImplementedBy(typeof(DAO.SistemaRI.NhDao<>)).Parameters(Parameter.ForKey("factory")
.Eq("${" +
GetSessionFactoryProviderKey(sessionFactoryName1) + "}")));


container.Register(Component.For(typeof(DAO.IServico<>)).ImplementedBy(typeof(DAO.Servico<>)).LifeStyle.Transient);

container.Register(Component.For(typeof(DAO.SistemaRI.IServico<>)).ImplementedBy(typeof(DAO.SistemaRI.Servico<>)).LifeStyle.Transient);

var config1 = new ConfigurationProvider(configurationsDB1, bancoRI,
sessionFactoryName1, configurationsDB2, bancoPO, sessionFactoryName2);
var sfp = new MultiSessionFactoryProvider(config1);

container.Register(Component.For<ISessionFactoryProvider>().Instance(sfp));

var sl = new WindsorServiceLocator(container);

container.Register(Component.For<IServiceLocator>().Instance(sl));

Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(()
=> sl);

My RegisterSessionFactoryFor method does:

windsorContainer.Register(Component.For<ISessionFactory>().Named(GetSessionFactoryProviderKey(sessionFactoryName))
.Configuration(Attrib.ForName("factoryId").Eq(sessionFactoryProviderComponentKey),

Attrib.ForName("factoryCreate").Eq("GetFactory")).Parameters(Parameter.ForKey("factoryId").Eq(sessionFactoryName)));

Reply all
Reply to author
Forward
0 new messages