Could you describe the reasoning behind the design and how it is used? I wont suggest that you change it, but I need to understand it in order to propose something.
2013/8/22 Patrick Doran <[email protected]> > The database setup we are using currently is 3 "standard" databases where > their mapping schema is mapped to "database.schema", however we also have a > set of mapped items where the mapping of the schema is to .schema. This > database schema/architecture design may sound unorthodox but it something I > can't change, so please don't suggest that. > > The current use for this DAL is in a MVC web application, we are using > Autofac MVC dependency resolver to scope a session the full lifetime of a > web request. We then use Castle Proxies to intercept requests to our > Services that are marked with a transaction attribute or requests to > Repositories, and sniff the httpcontext information to determine which > database to point to. We create a unit of work with the interceptor, which > based on the sniffed database value calls > Session.Connection.ChangeDatabase(database); This solution works great > with lazy loading turned off. > > We had a different setup before that was not very flexible and have moved > to this setup. Previously we had lazy loading turned off and we are trying > to, with our new solution, turn it back on. In our integration tests we are > able to lazy load successfully with the static schema objects, however the > "dynamic schema" database lazy loading is problematic, because when it goes > to lazy load it will encounter an ADOException "Invalid object name > '.schema.table'", which makes sense. > > We also need to be able to switch databases during a transaction, so we > can't tie the session directly to the database we want to connect to. > > I am curious if there is anyway to intercept the lazy loading requests and > execute a Session.Connection.ChangeDatabase command. This of course also > has the requirement that I can somehow store which database a particular > entity came from so that I can reapply when I intercept the request which > database to target. My guess is I may need to implement an interceptor and > wire it in differently IE config.SetInterceptor (in the code below) and > perhaps during Instantiate I could set some property that is available to > all "Dynamic Database" models IE Database, and then during lazy load > intercept and issue the ChangeDatabase on the session. > > Here is what the Autofac registeration looks like that we use now: > > > builder.Register(c => { > string connectionString = > String.Format(Configuration.Settings.Infrastructure.ConnectionString, > DEFAULT_DATABASE); > var config = new Configuration(); > config.DataBaseIntegration(db => { > db.Driver<SqlClientDriver>(); > db.Dialect<MsSql2008Dialect>(); > db.ConnectionString = connectionString; > }); > config.AddAssembly(typeof(UnitOfWork).Assembly); > // maybe config.SetInterceptor(new SomeCustomInterceptor()) > ISessionFactory factory = config.BuildSessionFactory(); > return new RedactedSessionFactory(DEFAULT_DATABASE, factory); > }).As<IRedactedSessionFactory>() > .SingleInstance(); > > > // Repository Interceptor. > builder.Register((c, p) => { > IRedactedSessionFactory factory = > c.Resolve<IRedactedSessionFactory>(); > string name = GetDatabaseNameFromEnvironment(c, p); > name = name ?? DEFAULT_DATABASE; > factory.Database = name; > return new UnitOfWorkInterceptor(factory, name); > }).InstancePerLifetimeScope(); > > -- > 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 http://groups.google.com/group/nhusers. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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 http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/groups/opt_out.
