Sandor Drieënhuizen
Sandor Drieënhuizen

Reputation: 6398

How to get hold of the current NHibernate.Cfg.Configuration instance

My C# project has repositories that are instantiated using dependency injection.

One of the repository methods needs access to the NHibernate.Cfg.Configuration instance (to generate the database schema) that was returned when initializing NHibernate.

I cannot pass the configuration to the repository however, because that would break the persistence ignorance principle -- I really don't want to expose any implementation details through the repository interface.

So what I'm looking for is a way of getting hold of the current NHibernate.Cfg.Configuration instance from within my repository. I have no trouble getting hold of the current session, it's just the configuration that I cannot get hold of.

Upvotes: 4

Views: 1048

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52753

It is not possible. The SessionFactory does not keep any references to the Configuration that built it.

Anyway, as Mauricio said: schema generation is not a Repository concern.

Upvotes: 2

Related Questions