<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Making frameworks container-aware</title>
	<atom:link href="http://lostechies.com/jimmybogard/2008/12/15/making-frameworks-container-aware/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2008/12/15/making-frameworks-container-aware/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Sun, 19 May 2013 03:22:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Fabio Maulo</title>
		<link>http://lostechies.com/jimmybogard/2008/12/15/making-frameworks-container-aware/#comment-1080</link>
		<dc:creator>Fabio Maulo</dc:creator>
		<pubDate>Sun, 21 Dec 2008 09:29:03 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/12/14/making-frameworks-container-aware.aspx#comment-1080</guid>
		<description>@bogardj
use this method 
public void SetListeners(ListenerType type, object[] listeners)
if you want initialize NH with instance of your listeners

@Jonathan
http://fabiomaulo.blogspot.com/2008/11/entities-behavior-injection.html
</description>
		<content:encoded><![CDATA[<p>@bogardj<br />
use this method<br />
public void SetListeners(ListenerType type, object[] listeners)<br />
if you want initialize NH with instance of your listeners</p>
<p>@Jonathan<br />
<a href="http://fabiomaulo.blogspot.com/2008/11/entities-behavior-injection.html" rel="nofollow">http://fabiomaulo.blogspot.com/2008/11/entities-behavior-injection.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://lostechies.com/jimmybogard/2008/12/15/making-frameworks-container-aware/#comment-1079</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Mon, 15 Dec 2008 11:50:25 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/12/14/making-frameworks-container-aware.aspx#comment-1079</guid>
		<description>We&#039;ve tried to avoid listeners for object creation because things can get complicated quickly - as you have discovered.

NHibernate isn&#039;t the most IoC friendly framework.  What we ended up doing was creating a private field in our repositories that looked like this:

private Action&lt;T&gt; initialize;

This private field served as a callback that populated our object instance - typically through setter injection (ugh!)

We used setter injection rather than constructor injection for several reasons, but the most important was to allow NHibernate to create a proxy object for us so that we gained the benefits of deferred query execution.

Here is our &quot;load&quot; method on our repository:

public virtual T FindById(int id)
{
  var loaded = (T)this.session.Load(this.type, id);
  this.initialize(loaded);
  return loaded;
}

In this instance &quot;T&quot; would be something like IContact, IAddress, IUser, etc. whereas &quot;this.type&quot; would be a concrete implementation for the respective interface.

We are actually performing dependency injection on our repositories to inject the session, type, and initialize objects.

In this manner we make NHibernate a bit more IoC friendly.
</description>
		<content:encoded><![CDATA[<p>We&#8217;ve tried to avoid listeners for object creation because things can get complicated quickly &#8211; as you have discovered.</p>
<p>NHibernate isn&#8217;t the most IoC friendly framework.  What we ended up doing was creating a private field in our repositories that looked like this:</p>
<p>private Action<t> initialize;</p>
<p>This private field served as a callback that populated our object instance &#8211; typically through setter injection (ugh!)</p>
<p>We used setter injection rather than constructor injection for several reasons, but the most important was to allow NHibernate to create a proxy object for us so that we gained the benefits of deferred query execution.</p>
<p>Here is our &#8220;load&#8221; method on our repository:</p>
<p>public virtual T FindById(int id)<br />
{<br />
  var loaded = (T)this.session.Load(this.type, id);<br />
  this.initialize(loaded);<br />
  return loaded;<br />
}</p>
<p>In this instance &#8220;T&#8221; would be something like IContact, IAddress, IUser, etc. whereas &#8220;this.type&#8221; would be a concrete implementation for the respective interface.</p>
<p>We are actually performing dependency injection on our repositories to inject the session, type, and initialize objects.</p>
<p>In this manner we make NHibernate a bit more IoC friendly.<br />
</t></p>
]]></content:encoded>
	</item>
</channel>
</rss>
