Scary StructureMap configuration expressions Pt.1

07 Apr 2009 in csharp | libs-and-frameworks |

“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()); })); </csharp> 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.


comments powered by Disqus