<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://codeprairie.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>chrisortman : NHibernate</title><link>http://codeprairie.net/blogs/chrisortman/archive/tags/NHibernate/default.aspx</link><description>Tags: NHibernate</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Hooking into new Nhibernate features from Castle ActiveRecord</title><link>http://codeprairie.net/blogs/chrisortman/archive/2008/04/09/hooking-into-new-nhibernate-features-from-castle-activerecord.aspx</link><pubDate>Wed, 09 Apr 2008 15:39:45 GMT</pubDate><guid isPermaLink="false">73a4aa19-1c0c-4438-a31e-8c1402e1ba60:409</guid><dc:creator>chrisortman</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://codeprairie.net/blogs/chrisortman/rsscomments.aspx?PostID=409</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://codeprairie.net/blogs/chrisortman/commentapi.aspx?PostID=409</wfw:comment><comments>http://codeprairie.net/blogs/chrisortman/archive/2008/04/09/hooking-into-new-nhibernate-features-from-castle-activerecord.aspx#comments</comments><description>&lt;p&gt;
&lt;a href="http://www.nhibernate.org"&gt;NHibernate&lt;/a&gt; has a lot of great new features. One of which is support for events.
&lt;/p&gt;

&lt;p&gt;However, if you are using &lt;a href="http://www.castleproject.org/activerecord"&gt;Castle ActiveRecord&lt;/a&gt; you can&amp;#39;t specify these things in the configuration like you normally could and must instead roll up your sleeves and do it programatically.
&lt;/p&gt;

&lt;p&gt; There are 2 hooks in ActiveRecord that we can use to accomplish our goal. &lt;/p&gt;

&lt;p&gt; The first is SessionFactoryHolderCreated which will notify you that the thing that holds the NHibernate ISessionFactory is ready. The next is RootTypeRegistered which happens after the active record configuration has been turned into NHibernate configuration.
&lt;/p&gt;

&lt;p&gt; Here is a simple example &lt;/p&gt;

&lt;div style="font-family:Consolas;font-size:11pt;color:white;background:black;font-weight:bold;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;font-weight:normal;"&gt;IConfigurationSource&lt;/span&gt; source = &lt;span style="color:#ffc66d;"&gt;ConfigurationSettings&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.GetConfig(&lt;/span&gt;&lt;span style="color:#a5c25c;"&gt;&amp;quot;activerecord&amp;quot;&lt;/span&gt;) &lt;span style="color:#cc7832;"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af;font-weight:normal;"&gt;IConfigurationSource&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:#ffc66d;"&gt;ActiveRecordStarter&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.SessionFactoryHolderCreated += (holder) =&amp;gt; {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; holder.OnRootTypeRegistered += (sender, rootType) =&amp;gt; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#cc7832;"&gt;var&lt;/span&gt; mholder = sender &lt;span style="color:#cc7832;"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af;font-weight:normal;"&gt;ISessionFactoryHolder&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#cc7832;"&gt;var&lt;/span&gt; nhConfig = mholder.GetConfiguration( rootType);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; nhConfig.EventListeners. PreUpdateEventListeners =&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color:#cc7832;"&gt;new&lt;/span&gt; NHibernate.Event. &lt;span style="color:#2b91af;font-weight:normal;"&gt;IPreUpdateEventListener&lt;/span&gt;[] {&lt;span style="color:#cc7832;"&gt;new&lt;/span&gt; &lt;span style="color:#ffc66d;"&gt;MyEventListener&lt;/span&gt;()}; &lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp; };&lt;/p&gt;
&lt;p style="margin:0px;"&gt;};&lt;/p&gt;
&lt;/div&gt;


&lt;p&gt;Technorati Tags:
&lt;a href="http://technorati.com/tag/castle" rel="tag"&gt;castle&lt;/a&gt;, &lt;a href="http://technorati.com/tag/nhibernate" rel="tag"&gt;nhibernate&lt;/a&gt;, &lt;a href="http://technorati.com/tag/.net" rel="tag"&gt;.net&lt;/a&gt;
&lt;/p&gt;
&lt;img src="http://codeprairie.net/aggbug.aspx?PostID=409" width="1" height="1"&gt;</description><category domain="http://codeprairie.net/blogs/chrisortman/archive/tags/.NET/default.aspx">.NET</category><category domain="http://codeprairie.net/blogs/chrisortman/archive/tags/Castle/default.aspx">Castle</category><category domain="http://codeprairie.net/blogs/chrisortman/archive/tags/NHibernate/default.aspx">NHibernate</category></item><item><title>Quick Resharper Tip</title><link>http://codeprairie.net/blogs/chrisortman/archive/2008/04/08/quick-resharper-tip.aspx</link><pubDate>Wed, 09 Apr 2008 02:26:33 GMT</pubDate><guid isPermaLink="false">73a4aa19-1c0c-4438-a31e-8c1402e1ba60:407</guid><dc:creator>chrisortman</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://codeprairie.net/blogs/chrisortman/rsscomments.aspx?PostID=407</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://codeprairie.net/blogs/chrisortman/commentapi.aspx?PostID=407</wfw:comment><comments>http://codeprairie.net/blogs/chrisortman/archive/2008/04/08/quick-resharper-tip.aspx#comments</comments><description>&lt;p&gt;
	I&amp;#39;m upgrading my &lt;a href="http://www.nhibernate.org"&gt;NHibernate&lt;/a&gt; references to the new Alpha build and have to change a bunch of using declarations from NHibernate.Expressions to NHibernate.Criterion.
&lt;/p&gt;

&lt;p&gt;
	A simple way to have &lt;a href="http://www.jetbrains.com/resharper"&gt;Resharper&lt;/a&gt; do this for you is to declare you own NHibernate.Expression namespace and rename it.
&lt;/p&gt;

&lt;p&gt; 
Resharper will then find anywhere you declared a using for it and update it. When you are done just remove your namespace declaration.
&lt;/p&gt;




&lt;p&gt;Technorati Tags:
&lt;a href="http://technorati.com/tag/nhibernate" rel="tag"&gt;nhibernate&lt;/a&gt;, &lt;a href="http://technorati.com/tag/resharper" rel="tag"&gt;resharper&lt;/a&gt;
&lt;/p&gt;
&lt;img src="http://codeprairie.net/aggbug.aspx?PostID=407" width="1" height="1"&gt;</description><category domain="http://codeprairie.net/blogs/chrisortman/archive/tags/Resharper/default.aspx">Resharper</category><category domain="http://codeprairie.net/blogs/chrisortman/archive/tags/NHibernate/default.aspx">NHibernate</category></item></channel></rss>