Scary StructureMap configuration expressions Pt.1

April 07, 2009 in

"Most scary StructureMap Configuration Expression"™ so far... ForRequestedType() .InterceptConstructionWith(wcfCachePolicy) .AddInstances(instanceExpression => instanceExpression.Conditional( cond => { cond.TheDefault.Is.ConstructedBy( ctx => ctx.GetInstance() .OpenSession( new IsisNHInterceptor(ctx.GetInstance()))); cond.If(ctx => ctx.ParentType.Name.Contains("ReadOnly")).ThenIt.Is. ConstructedBy( ctx =>ctx.GetInstance().OpenSession()); }));

The idea: In order to correctly talk to a decidedly legacy-i Database correct, write operations need to set a number of session variables for the used connection. This is done by an NHibernate Session interceptor. The convention is then that the Repository using the NHibernate session does not contain the text "ReadOnly" in its class name. If it does, the repository promises to only read the database which is unlikely (I hope) to trigger any..err..triggers. In this case the Interceptor isn't necessary.

Comfortable command line argument parsingHow much does Linq.Take take?