<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DeepElement</title>
	<atom:link href="http://www.deepelement.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deepelement.com/blog</link>
	<description>DeepElement Software Services</description>
	<lastBuildDate>Fri, 18 May 2012 02:36:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Introducing WebStack Container</title>
		<link>http://www.deepelement.com/blog/2012/03/introducing-webstack-container/</link>
		<comments>http://www.deepelement.com/blog/2012/03/introducing-webstack-container/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 01:09:11 +0000</pubDate>
		<dc:creator>toddpi314</dc:creator>
				<category><![CDATA[Net]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WebStack InversionOfControl IoC NuGet GitHub Aspect-Oriented Components Asp.net]]></category>

		<guid isPermaLink="false">http://www.deepelement.com/blog/2012/03/04/introducing-webstack-container/</guid>
		<description><![CDATA[WebStack is a component model for aspect-oriented Server State that can be used with ASP.NET and NInject. Components will allow your team to create stateful dependencies which can be injected and used through-out your web application without worrying about the scope of the dependency. It also provides an easy mechanism to quickly transfer state from [...]]]></description>
			<content:encoded><![CDATA[<p>WebStack is a component model for aspect-oriented Server State that can be used with ASP.NET and NInject. </p>
<p>Components will allow your team to create stateful dependencies which can be injected and used through-out your web application without worrying about the scope of the dependency. It also provides an easy mechanism to quickly transfer state from one scope to the other, with ease.&#160; </p>
<p>The container uses reflection-based scaffolding on your Applications assemblies to auto-register your components and makes sure they follow a life-cycle you can rely on.</p>
<p>Each component, once discovered and bound, takes part in a direct life-cycle which maps to web requests and will allow safe create/disposal logic within your app.</p>
<p>&#160;</p>
<h1>What is a Component, really?</h1>
<p>A WebStack component is an concrete type that implements IComponent. </p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb.png" width="461" height="175" /></a></p>
<p>There are three types of components:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb1.png" width="645" height="481" /></a></p>
<p>When you create your components, just decide which scope you would like the instance to be registered within and the WebStack Container Module will make sure that instances are resolved based on the Web Context of your application.</p>
<p>Typically, components represent an ‘aspect’ of work which can be implemented without the concerns of the framework in which it is hosted.</p>
<p>&#160;</p>
<h1>Component Scope Registrations</h1>
<p>The WebStack Container API supports two different binding approaches.</p>
<h2>Annotation-Driven Registration</h2>
<p>Any class that inherits from <em>IComponent</em> and contains a Scope attribute will be registered in the associated instance scope.</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image3.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb2.png" width="402" height="281" /></a></p>
<p>The supported Scope attributes are <em>ApplicationScoped</em>, <em>SessionScoped</em> and <em>RequestScoped</em>.</p>
<p>&#160;</p>
<h2>Interface-Driven Registration </h2>
<p>Any class that inherits from either <em>IApplicationComponent</em>, <em>ISessionComponent</em> or <em>IRequestComponent</em> will be registered in the associated instance scope.</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image4.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb3.png" width="425" height="257" /></a></p>
<p>&#160;</p>
<h2>Composite Interface Bindings</h2>
<p>You can also inherit from any baseclass or implement any interface on your concrete instances, in addition to the component registration requirements.</p>
<p>The WebStack Container will make sure you get the right instance in the right scope, no matter how you request it.</p>
<p>For instance, if you have a business process interface defined as:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image5.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb4.png" width="240" height="46" /></a></p>
<p>Which you have determined is a Workflow that should be instanced per User/Session, you would create your concrete implementation as follows:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image6.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb5.png" width="539" height="348" /></a></p>
<p>Now, all requested injections of IMyBusinessProcess would resolve to a new instance per user session!</p>
<p>You will receive clear life-cycle events and may implement your workflow free of web concerns.</p>
<p>&#160;</p>
<h1>Building Your Components</h1>
<p>There are three patterns I recommended for Component design:</p>
<h2>Isolated Components</h2>
<p>With an Isolated Component, the component does not contain an API definition and is designed to work only against the Component Life-Cycle.</p>
<ol>
<li>1. Build your component without an custom interface </li>
<li>2. Register it in one of the three supported scopes </li>
<li>3. Rely on the life-cycle to drive the components unit-of-work. </li>
</ol>
<p>As an example, consider a Component that updates the DB’s Keep-Alive record for a signed in user:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image7.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb6.png" width="475" height="259" /></a></p>
<p>In this example, the KeepAliveService does not implement its own api and it’s process is coupled to only the Request Component Life-Cycle.</p>
<p>&#160;</p>
<h2></h2>
<h2>Individual Components</h2>
<p>An Individual Component acts as an application-accessible api that uses the Component Life-cycle to control its transaction boundaries.</p>
<ol>
<li>1. Build your component against a proprietary service definition </li>
<li>2. Register the component in one of the three supported scopes </li>
<li>3. Allow the Component Life-Cycle to build up the component state for use as an API against the proprietary service definition </li>
</ol>
<p>As an example, consider a Component that logs how many times a Web User opens an email during the life-time of their Session.</p>
<p>We would create an interface that will be called from our Web Controllers to trigger the event:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image8.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb7.png" width="248" height="50" /></a></p>
<p>Then, in our component implementation we would allow the count of emails to be held until the end of the user’s session, where we could commit the result to the DB:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image9.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb8.png" width="434" height="338" /></a></p>
<p>The Web Application could then request instances of the IEmailTracker without the concerns of its transaction scope.</p>
<p>&#160;</p>
<h2>Community Components</h2>
<p>An Community Component is a Stateful workflow which uses the Component Life-cycle to control its transaction bounds, but also has dependencies on other components. </p>
<ol>
<li>1. Build your component against a proprietary service definition </li>
<li>2. Register the component in one of the three supported scopes </li>
<li>3. Inject instances of other components needed to perform work </li>
<li>4. Allow the Component Life-Cycle to build up the component state for use as an API against the proprietary service definition </li>
</ol>
<p>As an example, consider a requirement to Log Open-Email events in our SessionEmailTracker (see “Individual Component” example above).</p>
<p>We can create a new component that will allow us to commit logging events <em>per request</em> , even from a Session scoped component:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image10.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb9.png" width="208" height="48" /></a></p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image11.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb10.png" width="343" height="350" /></a></p>
<p>We simply inject this into our Email Tracker component as follows:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image12.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb11.png" width="437" height="406" /></a></p>
<p>Now, even though the SessionEmailTracker is executing as a Session Component, it will resolve the logger to a Request Scoped component. </p>
<p>Then, at the end of each request the logging message will be committed to the DB.</p>
<p>&#160;</p>
<h1>Manually Get the Components</h1>
<p>For those that have their own patterns, the NInject Kernel can be interacted with via the <em>IContainerManager</em> instance on the ContainerModule.</p>
<p>Simply call <em>BuildUp(this)</em> on your class to have properties with the [Inject] attribute resolved.</p>
<p>Here is a sample WebForm using this pattern:</p>
<p><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image13.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 40px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb12.png" width="444" height="231" /></a>&#160;</p>
<p>&#160;</p>
<h2></h2>
<h1>Project Source</h1>
<div align="justify">
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><font color="#000000"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb13.png" width="76" height="41" /></font></td>
<td valign="top" width="200">
<p align="justify">&#160;<a href="mailto:git@github.com:DeepElement/DeepElement.WebStack.git" target="_blank">git@github.com:DeepElement/DeepElement.WebStack.git</a></p>
</td>
</tr>
<tr>
<td valign="top" width="200"><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image40.png"><font color="#000000"></font></a><a href="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image41.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.deepelement.com/blog/wp-content/uploads/2012/03/image_thumb14.png" width="87" height="27" /></a></a></a></td>
<td valign="top" width="200">&#160;<a href="http://nuget.org/packages/WebStack.Modules.Container" target="_blank">http://nuget.org/packages/WebStack.Modules.Container</a></td>
</tr>
</tbody>
</table></div>
<div align="justify">&#160;</div>
<div align="justify">I am currently using this container for multiple production web applications.</div>
<div align="justify">Shoot me some feedback about your usages and how I can make it better!</div>
<div align="justify">&#160;</div>
<div align="justify">Todd Morrison</div>
]]></content:encoded>
			<wfw:commentRss>http://www.deepelement.com/blog/2012/03/introducing-webstack-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

